Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Dependent" non-typename template arguments

0 views
Skip to first unread message

AJG

unread,
Aug 24, 2010, 5:02:47 PM8/24/10
to
Is something like the following allowed?

template <typename T, T V>
struct foo {};

foo<bool, true>

MSVC accepts it happily, but that's never a reliable indicator.

What about:

template <typename T>
struct foo {
template <T V>
struct bar {};
};

foo<bool>::bar<true>

Thanks.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

CornedBee

unread,
Aug 24, 2010, 8:06:19 PM8/24/10
to
On Aug 24, 2:02 pm, AJG <plus....@gmail.com> wrote:
> Is something like the following allowed?
>
> template <typename T, T V>
> struct foo {};
>
> foo<bool, true>
>

Yes.

>
> What about:
>
> template <typename T>
> struct foo {
> template <T V>
> struct bar {};
>
> };
>
> foo<bool>::bar<true>
>

And yes.

I'm pretty sure I remember that something in Boost uses this
construct.

Sebastian

GMan

unread,
Aug 25, 2010, 1:22:53 PM8/25/10
to
On Aug 24, 5:06 pm, CornedBee <wasti.r...@gmx.net> wrote:
>
> I'm pretty sure I remember that something in Boost uses this
> construct.
>

You're probably thinking of integral_constant, which is also present
in the C++0x draft.

template <typename T, T Value>
struct integral_constant
{
static const value_type value = Value;

// and stuff
};

0 new messages