Literal operator templates

I

Inconnu

In the new standard the literal operator templates are restricted to
have a single non-type template parameter of type char which is a
pack. This restriction makes illegal the following construction for
binary integer literals:

template<char C0, char ...C>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return sizeof... (C) == 0 ? C0 - '0' : ((C0 - '0') << sizeof...
(C)) + operator "" b<C...> ();
}

I think it would be better to require instead that all template
parameters be non-type parameters of type char, while the last of them
may be a parameter pack.
 
J

Johannes Schaub (litb)

Inconnu said:
In the new standard the literal operator templates are restricted to
have a single non-type template parameter of type char which is a
pack. This restriction makes illegal the following construction for
binary integer literals:

template<char C0, char ...C>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return sizeof... (C) == 0 ? C0 - '0' : ((C0 - '0') << sizeof...
(C)) + operator "" b<C...> ();
}

I think it would be better to require instead that all template
parameters be non-type parameters of type char, while the last of them
may be a parameter pack.

The shown definition would be illegal anyway, because there is no template
to use for `operator "" b<>` .

Can you show an example where it would be clearly advantageous?
 
I

Inconnu

The shown definition would be illegal anyway, because there is no template
to use for `operator "" b<>` .

Can you show an example where it would be clearly advantageous?

Can you show an example where `operator "" b<>` is used?
 
I

Inconnu

The shown definition would be illegal anyway, because there is no template
to use for `operator "" b<>` .

Can you show an example where it would be clearly advantageous?

Can you show an example where `operator "" b<>` is used?
 
I

Inconnu

 Can you show an example where `operator "" b<>` is used?

I understood. The `operator "" b<>` is required when types of
expressions are calculated. Then my example may be changed so:

template<char ...C> unsigned long long operator "" b();

template<char C0, char ...C>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return sizeof... (C) == 0 ? C0 - '0' : ((C0 - '0') << sizeof...
(C)) + operator "" b<C...> ();

}
 
I

Inconnu

Or even better variant, which doesn't refer to `operator "" b<>`
(which by itself, from the literal, can't be evoked, because character
sequence of a user-defined-literal always contains at least 1
element):

template<char C0, char ...C>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return ((C0 - '0') << sizeof... (C)) + operator "" b<C...> ();

}

template<char C0>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return ((C0 - '0');
}
 
L

Leo Equinox Gaspard

Le 06/07/2011 17:53, Inconnu a écrit :
In the new standard the literal operator templates are restricted to
have a single non-type template parameter of type char which is a
pack. This restriction makes illegal the following construction for
binary integer literals:

template<char C0, char ...C>
constexpr unsigned long long operatorl "" b ()
{
static_assert (C0 == '0' || C0 == '1');
return sizeof... (C) == 0 ? C0 - '0' : ((C0 - '0')<< sizeof...
(C)) + operator "" b<C...> ();
}

I think it would be better to require instead that all template
parameters be non-type parameters of type char, while the last of them
may be a parameter pack.

I'm not yet used to user-defined literals, but ... Why do you define
{{ operatorl "" b() }} and not {{ operator "" b () }} ?

A research in the last working draft freely available didn't get anything.

Thanks in advance,
Leo
 
A

Alf P. Steinbach /Usenet

* Leo Equinox Gaspard, on 07.07.2011 11:58:
Le 06/07/2011 17:53, Inconnu a écrit :

I'm not yet used to user-defined literals, but ... Why do you define
{{ operatorl "" b() }} and not {{ operator "" b () }} ?

A research in the last working draft freely available didn't get anything.

Thanks in advance,
Leo

This is very ugly.

Who is the person that introduced this stuff and that should now be killed?


- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top