Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using implicit function template specialization to check if an identifier is an array

Reply
Thread Tools

Using implicit function template specialization to check if an identifier is an array

 
 
Angel Tsankov
Guest
Posts: n/a
 
      01-13-2007
>>> I'm thinking about using a function tamplate to verify that
>>> an
>>> identifier is of an array type. May the following template be
>>> used for this purpose:
>>>
>>> template< typename T, int N >
>>> void check_array( T(&)[N] )
>>> {
>>> }

>>
>> How do you envision using the check_array() function template
>> to a test
>> for an array type exactly? If anything, std::tr1::is_array (or
>> std::is_array in the future) is pretty easy to use:


Where can I get an implementation of tr1?

 
Reply With Quote
 
 
 
 
Greg
Guest
Posts: n/a
 
      01-13-2007
Angel Tsankov wrote:
> I'm thinking about using a function tamplate to verify that an
> identifier is of an array type. May the following template be
> used for this purpose:
>
> template< typename T, int N >
> void check_array( T(&)[N] )
> {
> }


How do you envision using the check_array function template to test for
an array type? I think std::tr1::is_array would probably be more
convenient:

#include <iostream>
#include <ios>
#include <tr1/type_traits>

using std::tr1::is_array;

int main()
{
bool b = is_array< int[5] >::value;

std::cout << std::boolalpha << b << "\n";
}

Program Output:

true

Greg

 
Reply With Quote
 
 
 
 
Angel Tsankov
Guest
Posts: n/a
 
      01-14-2007
>> I'm thinking about using a function tamplate to verify that an
>> identifier is of an array type. May the following template be
>> used for this purpose:
>>
>> template< typename T, int N >
>> void check_array( T(&)[N] )
>> {
>> }

>
> How do you envision using the check_array function template to
> test for
> an array type? I think std::tr1::is_array would probably be
> more
> convenient:
>
> #include <iostream>
> #include <ios>
> #include <tr1/type_traits>
>
> using std::tr1::is_array;
>
> int main()
> {
> bool b = is_array< int[5] >::value;
>
> std::cout << std::boolalpha << b << "\n";
> }
>
> Program Output:
>
> true


Can one use std::tr1::is_array with array, e.g.:

int array[5];
bool const b = std::tr1::is_array<array>::value;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I fix the warning C4786 'identifier' : identifier wastruncated to 'number' characters in the debug information...? babakandme@yahoo.com C++ 2 12-11-2007 08:17 PM
identifier not found error, undeclared identifier aarthi28@gmail.com C++ 2 02-26-2007 02:11 AM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
template, implicit specialization? C++ 1 09-18-2005 04:28 AM
Trying to declare identifier locally and hide a file scope identifier Kobu C Programming 7 02-25-2005 05:19 AM



Advertisments