--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Hana's operator""_s is actually a template (which depends on a compiler extension).
So it'd actually be operator""_s<char, 's', 'a', 'm', 'p', 'l', 'e'>().
That's arguably even worse.
Boost::Hana provides a user-defined literal that I would like to use to define a compile time string in a header.
See http://ldionne.com/hana/structboost_1_1hana_1_1String.html#ad77f7afff008c2ce15739ad16a8bf0a8
I would really like to say
struct A
{
using name_t = decltype("sample"_s);
#include <string>
auto hello = "hello"s; //of course not
auto world = "world"std::literals::string_literals::operator""s;
auto any = "any"(std::literals::string_literals::operator""s);
auto ideas = std::literals::string_literals::operator""s("ideas?");
But, again, what's the point?
#include <string>
auto hello = "hello"s; //of course not
auto world = "world"std::literals::string_literals::operator""s;
auto any = "any"(std::literals::string_literals::operator""s);
auto ideas = std::literals::string_literals::operator""s("ideas?");
As, the literals namespaces are inline, this could be simplified to use std::opeator""s. However I think that better syntax would be to place the qualification before literal itself, so we would get:
auto hello = "hello"s;
auto world = std::"world"s;
auto any = std::literals::string_literals::"any"s; //If you insist on writing more
and
auto s = boost::hana::"sample"_s;
Having prefixed qualified literal would allow to remove the limittion to use _ in user defined literals, because situation would now be same as for any other entity.
On Tue, Jun 16, 2015 at 1:12 AM, Roland Bock <rb...@eudoxos.de> wrote:
Boost::Hana provides a user-defined literal that I would like to use to define a compile time string in a header.
See http://ldionne.com/hana/structboost_1_1hana_1_1String.html#ad77f7afff008c2ce15739ad16a8bf0a8
I would really like to say
struct A
{
using name_t = decltype("sample"_s);
If we remove the (now-redundant) restriction on lambdas in unevaluated operands, you could write:
using name_t = decltype([] -> decltype(auto) {using namespace boost::hana;return "sample"_s;});
And in today's C++:
static decltype(auto) name() {using namespace boost::hana;return "sample"_s;}using name_t = decltype(name());
struct alias_t { static constexpr const char _literal[] = "delta"; using name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; };
struct alias_t { using name_t = decltype(::boost::hana::"delta"s); };
On 2015-06-16 23:42, Richard Smith wrote:
Are there plans/proposals to do that? I stumbled over this restriction quite a few times.On Tue, Jun 16, 2015 at 1:12 AM, Roland Bock <rb...@eudoxos.de> wrote:
Boost::Hana provides a user-defined literal that I would like to use to define a compile time string in a header.
See http://ldionne.com/hana/structboost_1_1hana_1_1String.html#ad77f7afff008c2ce15739ad16a8bf0a8
I would really like to say
struct A
{
using name_t = decltype("sample"_s);
If we remove the (now-redundant) restriction on lambdas in unevaluated operands, you could write:
On Wed, Jun 17, 2015 at 12:19 AM, Roland Bock <rb...@eudoxos.de> wrote:
On 2015-06-16 23:42, Richard Smith wrote:
Are there plans/proposals to do that? I stumbled over this restriction quite a few times.On Tue, Jun 16, 2015 at 1:12 AM, Roland Bock <rb...@eudoxos.de> wrote:
Boost::Hana provides a user-defined literal that I would like to use to define a compile time string in a header.
See http://ldionne.com/hana/structboost_1_1hana_1_1String.html#ad77f7afff008c2ce15739ad16a8bf0a8
I would really like to say
struct A
{
using name_t = decltype("sample"_s);
If we remove the (now-redundant) restriction on lambdas in unevaluated operands, you could write:
I don't think it's on the core issues list. We discussed it while working on core issue 1607, but I think we thought it would be best handled separately.
--
YMMV; I find std::"Hello"s to be more readable. (Intuitively: std::"Hello"s is a std::string. The prefix remains a prefix, and doesn't switch into an internal position.)Also, I feel like there would be a potential ambiguity with e.g. "Hello"a::b — is that the b belonging to "Hello"a, or is it "Hello"b evaluated with respect to the a namespace? (Notice that there may also be a member b of the a namespace, which is completely unrelated.) At the moment I think it's impossible to create an actual grammatical ambiguity there, but it feels dangerous.
On the other hand, consider the attempt to create an X::wstring via the expression X::LR"(Hello)"s (respectively LR"(Hello)"X::s). How does this interact with the declaration of a variable named X::LR (respectively X::s)?
Then consider the parsing nightmare that is units::42m resp. 42units::m. (Those expressions' respective readability strikes me as a good argument in favor of Roland's units::42m syntax and against David's alternative suggestion.)
On 2015–06–19, at 9:04 AM, Richard Smith <ric...@metafoo.co.uk> wrote:Putting the nested-name-specifier before the user-defined-literal token seems like the better choice to me.
User-defined literals are a mess added on top of the pre-existing mess of literal prefixes and suffixes, and perhaps the best thing to do is just stay far away from them...?
W dniu piątek, 19 czerwca 2015 02:21:54 UTC+2 użytkownik Arthur O'Dwyer napisał:User-defined literals are a mess added on top of the pre-existing mess of literal prefixes and suffixes, and perhaps the best thing to do is just stay far away from them...?
I do not agree with that point.
[...] However in the current form they are not really usable [...] unable to resolve ambiguity [...] we have only avoided the problem by reserving names that does not start "_" for standard library - such solution is not viable for other libraries [...] the user cannot simply invoke operator"" literal instead of using 123litterals, because they will need to know which form is used:
operator"" literal(123);
operator"" literal("123");
operator"" literal<'1', '2', '3'>(); //The 3rd form is hardly to be considered usable outside of automatic compiler calls.
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/hAnVRTlsQZY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
I do not consider the make_bigint< "1234" >(), to be as readable and user friendly as 1234_big, which I consider as argument for having user-defined literals in the language. But I belive that requires to support some form of qualified literals type, to allow library creators to provide resonable literal for thier types, without causing ambiguity problems for users that combines multiple libraries in single program. Reserving certain preffix for suffix is not an scalable option.
On Thu, Jun 18, 2015 at 9:44 PM, Tomasz <toma...@gmail.com> wrote:
W dniu piątek, 19 czerwca 2015 02:21:54 UTC+2 użytkownik Arthur O'Dwyer napisał:
User-defined literals are a mess added on top of the pre-existing mess of literal prefixes and suffixes, and perhaps the best thing to do is just stay far away from them...?
I do not agree with that point.[...] However in the current form they are not really usable [...] unable to resolve ambiguity [...] we have only avoided the problem by reserving names that does not start "_" for standard library - such solution is not viable for other libraries [...] the user cannot simply invoke operator"" literal instead of using 123litterals, because they will need to know which form is used:
operator"" literal(123);
operator"" literal("123");
operator"" literal<'1', '2', '3'>(); //The 3rd form is hardly to be considered usable outside of automatic compiler calls.
It sounds to me as if you do agree with my point. :D
Here's a thought experiment: What if, instead of having to write something like std::"Hello"s to construct a string, we could use the more functional-style notation std::s("Hello")? Such "functional-notation literals" could reuse the existing rules for overload resolution (we could get rid of the three different forms of operator"") and wouldn't lead us into any weird corner cases in the grammar. We could even exploit function overloading to make std::s(42) mean "42 seconds" and std::s("Hello") mean "a string with value Hello"... although from the programmer's point of view it might be preferable in practice to disambiguate by spelling out the words — std::seconds(42) and std::string("Hello") respectively — so we'd like to make that possible, too.Now what if I told you that the capability for this elegant form of literal notation has existed in C++ since 1998?! :)
I'll admit, UDLs did make it possible for 42_c to mean std::integral_constant<int,42>{}; that is, UDLs are pretty much the only way (besides a macro) to wrap a value in angle brackets without actually writing a pair of angle brackets in the code. But if we'd started with that goal actually in mind, would we have settled on UDLs as the right way to achieve it?
I dunno, seems a more logical place for the namespace to go rather than the beginning (like, where else does that happen?!).
std::""s is just illogical. Even going by your own logic. It's s that is in std not ""s.
On 2015–06–22, at 3:18 PM, Tomasz <toma...@gmail.com> wrote:We define operator""s in the namespace std, not the s itself. Please remember that we allow operator ""if to be defined
, while there cannot be entity named if in any namespace. So the syntax std::if would be incompatible with complex literals. the std::""s, suggest that we want tu use operator ""s from std::namespace.
On 2015–06–22, at 3:47 PM, David Krauss <pot...@mac.com> wrote:The only keyword I can think of that can follow :: is template.
On 2015–06–22, at 3:18 PM, Tomasz <toma...@gmail.com> wrote:We define operator""s in the namespace std, not the s itself. Please remember that we allow operator ""if to be definedMore precisely, operator""if is defined in [complex.literals] §26.4.10/4. Users can’t declare things like that, though, because UDL names not beginning with an underscore are reserved to the standard.
operator"" literal<'1', '2', '3'>(); //The 3rd form is hardly to be considered usable outside of automatic compiler calls.
On 2015–06–24, at 12:47 PM, Myriachan <myri...@gmail.com> wrote:Although orthogonal to this discussion, I wish we were allowed to pass literal strings or constant-expression char arrays to variadic char templates. It'd be a neat solution to the decades-long annoyance that literal strings can't be template parameters.
On 2015–06–24, at 12:47 PM, Myriachan <myri...@gmail.com> wrote:
Although orthogonal to this discussion, I wish we were allowed to pass literal strings or constant-expression char arrays to variadic char templates. It'd be a neat solution to the decades-long annoyance that literal strings can't be template parameters.
Not orthogonal, I suggested that earlier.
Another approach, perhaps less intrusive to template parameter passing, is to let the string-literal/array argument initialize a template type parameter with a variadic character list in a partial specialization.
template< char ... c >struct narrow_string;
template< char32_t ... c >struct wide_string;
template< typename str >struct my_string_metafn;
template< char ... c >struct my_string_metafn< narrow_string < c ... > > { … };
template< char32_t ... c >struct my_string_metafn< wide_string < c ... > > { … };
my_string_metafn< "hello" >::type foo;my_string_metafn< U"hello" >::type bar;
This provides for 1-to-1 mapping of arguments to parameters and encourages encapsulation of variadic lists.
This is also similar to the pure-library approach of defining operator""cs for compile-time strings, and then always use those strings as the starting point. This was the direction things were going at Urbana. Anyone who wants to let a library do string transformations will need to say using std::operator""cs, and pass them as function arguments or through decltype.
Unless the proposals get more ambitious, it seems unlikely for compile-time strings to be tied closer to the core language for now. But the avenue is still open.
On 2015–06–24, at 4:07 PM, Roland Bock <rb...@eudoxos.de> wrote:On 2015-06-24 07:50, David Krauss wrote:
Anything "official" / links? How was the feedback?
On 2015–06–24, at 12:47 PM, Myriachan <myri...@gmail.com> wrote:
Although orthogonal to this discussion, I wish we were allowed to pass literal strings or constant-expression char arrays to variadic char templates. It'd be a neat solution to the decades-long annoyance that literal strings can't be template parameters.
Not orthogonal, I suggested that earlier.
Not sure if I understand this correctly. Wouldn't the compiler have to turn "hello" into std::narrow_string<'h','e','l','l','o'> automatically here?
And then we're back to square one, if I want to do this in a header and initialize a static constexpr member of a class... :-(
Is there a proposal for std::operator""cs already?
On 2015–06–24, at 4:07 PM, Roland Bock <rb...@eudoxos.de> wrote:
On 2015-06-24 07:50, David Krauss wrote:
Anything "official" / links? How was the feedback?
On 2015–06–24, at 12:47 PM, Myriachan <myri...@gmail.com> wrote:
Although orthogonal to this discussion, I wish we were allowed to pass literal strings or constant-expression char arrays to variadic char templates. It'd be a neat solution to the decades-long annoyance that literal strings can't be template parameters.
Not orthogonal, I suggested that earlier.
I just mean, a few messages earlier in this thread. “Why not let make_bigint< "1234" >() do it?” That’s all.
Not sure if I understand this correctly. Wouldn't the compiler have to turn "hello" into std::narrow_string<'h','e','l','l','o'> automatically here?
Yes, but I think that’s better than turning "hello" into 'h','e','l','l','o'. Not least because we seem to be dropping the NUL termination, which tends to suggest that the sequence should be inside something. (This is also the behavior of literal operator templates. It looks like a strike against named char arrays.)
And then we're back to square one, if I want to do this in a header and initialize a static constexpr member of a class... :-(
constexpr lambdas look pretty likely for C++17.
Is there a proposal for std::operator""cs already?
There’s N4121 which called it operator""sl, and N3933 which was presented but missed the deadline. It was very similar.
Reviewing N4121, it doesn’t encode the string in the type. You can still unpack it using an index_sequence, though.