Topic: NonTypeTemplateParameterType c++0x, legal user-defined template parameters?


Author: german diago <germandiago@gmail.com>
Date: Tue, 12 May 2009 10:11:50 CST
Raw View
Hello. Looking at the standard, I have no clear idea if user-defined
literals which are constexpr
can be used as template parameters. Can this be done?


class MyStr
{
   MyClass operator ""_str(...);
  //...
};


concept_map NonTypeTemplateParameterType<MyClass> {};

And now, could I do something like this?

register_type<"Class"_str>([] { return new Class; });

Thanks in advance.


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: daniel.kruegler@googlemail.com
Date: Wed, 13 May 2009 10:11:36 CST
Raw View
On May 12, 6:11 pm, german diago <germandi...@gmail.com> wrote:
> Hello. Looking at the standard, I have no clear idea if user-defined
> literals which are constexpr can be used as template parameters.
> Can this be done?
>
> class MyStr
> {
>    MyClass operator ""_str(...);
>   //...
>
> };
>
> concept_map NonTypeTemplateParameterType<MyClass> {};

NonTypeTemplateParameterType is a so-called support concept
per 14.10.4 [concept.support]. Support concepts are *always*
implicitly defined and it is impossible to user-define a concept map
for such a concept. This is a safety mechanism that must exist
to ensure that the type-system remains consistent.

 From this follows that above concept map is ill-formed.

And according to the requirements for valid non-type template
parameters (14.2 [temp.param]/4) above class type MyStr does
not satisfy the requirements for that.

> And now, could I do something like this?
>
> register_type<"Class"_str>([] { return new Class; });

No, this would be ill-formed as well.

HTH & Greetings from Bremen,

Daniel Kr   gler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]