Concept check for pointer

Started by
7 comments, last by dalleboy 21 years, 7 months ago
Does anyone know of a concept check in C++ that checks if a template parameter is a pointer to an object or an object?
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
I would have thought:

  #include <boost/static_assert.hpp>template <typename T>struct IsPointer{    enum { value = false };};template <typename T>struct IsPointer<T*>{    enum { value = true };};// ...template <typename T>class MyClass{    BOOST_STATIC_ASSERT(true == IsPointer<T>::value);};  

would do the trick.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
If you''re using the Boost libraries, then you may aswell use their concept checks. See boost/type_traits for details.
..and adding this will do the trick some more.


  template<typename T> struct IsPointer<const T*>{    enum { value = true };};template<typename T> struct IsPointer<T* const>{    enum { value = true };};template<typename T> struct IsPointer<const T* const>{    enum { value = true };};  

Thank you all, I was searching for the wrong thing when I searched Boost. I thought that what I was looking for was called "concept checks", but what I really was looking for was "type traits". Thank you.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
So if I pass a typedef (eg charPtr for char*), that will go through the <T*> template and not the generic <T> template? If so, why? And what about smart pointers?



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
smart pointers actually behave like objects, thats why they are smart (dont talk about auto_ptr, thats a stupid smart ptr:D)

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

quote:Original post by Kylotan
So if I pass a typedef (eg charPtr for char*), that will go through the template and not the generic template?

Yes

quote:
If so, why?

Because it''s a typedef to a char*?

Typedef''s don''t create new types - struct, class, union, & enum do that.


Loki::TypeTraits::isPointer yields a compile-time constant bool.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by Kylotan
So if I pass a typedef (eg charPtr for char*), that will go through the template and not the generic template? If so, why?

Because it is a partial specialisation on type pointer-to-T, which the Standard allows.
quote:
And what about smart pointers?

They''ll hit the generic template, as they''re fully-fledged types, not pointer types.

This topic is closed to new replies.

Advertisement