|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
|
|
detect if a type has a size_t memberHello
template <typename T> struct S { // how to detect T has a member static const size_t value ? // if T has value, define member of S, m1 of type T1, otherwise m2 of type T2 }; Regards, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> Hello > > template <typename T> > struct S { > // how to detect T has a member static const size_t value ? > // if T has value, define member of S, m1 of type T1, otherwise m2 of > type T2 > }; > > Regards, > > _______________________________________________ > Boost-users mailing list > Boost-users@... > http://lists.boost.org/mailman/listinfo.cgi/boost-users > HAS_STATIC_MEMBER_NAMED meta-function builder -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of joel > Sent: 03 July 2009 17:03 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member > > Hicham Mouline wrote: > > Hello > > > > template <typename T> > > struct S { > > // how to detect T has a member static const size_t value ? > > // if T has value, define member of S, m1 of type T1, otherwise > m2 of > > type T2 > > }; > > > > Regards, > > Check the Boost.Vault for th eintrospection library. It has a > HAS_STATIC_MEMBER_NAMED meta-function builder Can I put the macro inside the struct S ? I guess not. I'd write: HAS_STATIC_MEMBER_NAMED(T, value) which would return a integral bool or a bool type? _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> Can I put the macro inside the struct S ? I guess not. I'd write: > HAS_STATIC_MEMBER_NAMED(T, value) > > which would return a integral bool or a bool type it works liek BOOST_MPL_HAS_XXXX so put it where you want to define a boolean meta-function. It supports ::value and ::type return mpl boolean. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
|
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> which doesn't build because > > error C2953: 'boost::introspection::has_member_data_maxsize' : class > template has already been defined > The macro build a template meta-function that you use on your type : BOOST_HAS_MEMBER_DATA(size_t, maxsize); int main() { if ( boost::introspection::has_member_data_maxsize<T>::value ) { std::cout<<" T has max_size"<<std::endl; } return 0; } ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
Thank you. May I suggest to replace "Type" in
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of joel > Sent: 06 July 2009 14:26 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member > > Hicham Mouline wrote: > > which doesn't build because > > > > error C2953: 'boost::introspection::has_member_data_maxsize' : class > > template has already been defined > > > The macro build a template meta-function that you use on your type : > > BOOST_HAS_MEMBER_DATA(size_t, maxsize); > > > int main() > { > if ( boost::introspection::has_member_data_maxsize<T>::value ) > { > std::cout<<" T has max_size"<<std::endl; > } > return 0; > } > #define BOOST_HAS_MEMBER_DATA(Type,Name) in the header file by MemberType for e.g. A naive user (myself) thought "Type" was his type, not the member data type. Regards, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> Thank you. May I suggest to replace "Type" in > #define BOOST_HAS_MEMBER_DATA(Type,Name) > > in the header file by MemberType for e.g. > > A naive user (myself) thought "Type" was his type, not the member data type Will do :) -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> #include <boost/introspection/has_member_data.hpp> > > struct S { > static const size_t maxsize =5; > }; > > struct T { > }; > > BOOST_HAS_MEMBER_DATA(S, maxsize) > BOOST_HAS_MEMBER_DATA(T, maxsize) It's not BOOST_HAS_MEMBER_DATA you need, but BOOST_HAS_STATIC_MEMBER_NAMED. Indeed, BOOST_HAS_MEMBER_DATA is for non-static members. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
Thank you,
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of joel > Sent: 06 July 2009 14:26 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member > > Hicham Mouline wrote: > > which doesn't build because > > > > error C2953: 'boost::introspection::has_member_data_maxsize' : class > > template has already been defined > > > The macro build a template meta-function that you use on your type : > > BOOST_HAS_MEMBER_DATA(size_t, maxsize); > > > int main() > { > if ( boost::introspection::has_member_data_maxsize<T>::value ) > { > std::cout<<" T has max_size"<<std::endl; > } > return 0; > } 1) struct S { static const size_t maxsize =5; }; 2) struct S { static size_t maxsize; }; 3) struct S { size_t maxsize; }; Applied to S, the code doesn't compile in 1 and returns false in 2. Is there a fix that can make it work for 1, 2 and 3 ? Regards, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
>> BOOST_HAS_MEMBER_DATA(size_t, maxsize); >> >> >> int main() >> { >> if ( boost::introspection::has_member_data_maxsize<T>::value ) >> { >> std::cout<<" T has max_size"<<std::endl; >> } >> return 0; >> } > Thank you, > > 1) struct S { > static const size_t maxsize =5; > }; > > 2) struct S { > static size_t maxsize; > }; > > 3) struct S { > size_t maxsize; > }; > > > Applied to S, the code doesn't compile in 1 and returns false in 2. > > Is there a fix that can make it work for 1, 2 and 3 ? No. Static members and non-static ones are very different things, and each requires usage of a different macro. BOOST_HAS_STATIC_MEMBER_DATA and BOOST_HAS_MEMBER_DATA. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member2009/7/29 Mathias Gaunard <mathias.gaunard@...>
It explains why 2 returns false, but does not explain why 1 does not compile. Roman Perepelitsa. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberRoman Perepelitsa wrote:
> 2009/7/29 Mathias Gaunard <mathias.gaunard@... > <mailto:mathias.gaunard@...>> > > 1) struct S { > static const size_t maxsize =5; > }; > It explains why 2 returns false, but does not explain why 1 does not > compile. Because static const <integral type> = <some value> members are quite special beasts. Indeed, unlike other static members, you can't take their address, since they don't exist in memory but only as compile-time constants. Testing whether the type is integral is not enough either, since if there is no definition they behave like normal static members. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberMathias Gaunard wrote:
> It explains why 2 returns false, but does not explain why 1 does not > compile. Introspection is also in the vault as a WIP. Straneg behavior under soem compilers have to be expected. I'm working on this quite extensively. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of Mathias Gaunard > Sent: 29 July 2009 13:12 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member > > Hicham Mouline wrote: > > >> BOOST_HAS_MEMBER_DATA(size_t, maxsize); > >> > >> > >> int main() > >> { > >> if ( boost::introspection::has_member_data_maxsize<T>::value ) > >> { > >> std::cout<<" T has max_size"<<std::endl; > >> } > >> return 0; > >> } > > Thank you, > > > > 1) struct S { > > static const size_t maxsize =5; > > }; > > > > 2) struct S { > > static size_t maxsize; > > }; > > > > 3) struct S { > > size_t maxsize; > > }; > > > > > > Applied to S, the code doesn't compile in 1 and returns false in 2. > > > > Is there a fix that can make it work for 1, 2 and 3 ? > > No. > Static members and non-static ones are very different things, and each > requires usage of a different macro. > BOOST_HAS_STATIC_MEMBER_DATA and BOOST_HAS_MEMBER_DATA. I can't find BOOST_HAS_STATIC_MEMBER_DATA in introspection in the sandbox. Were you referring to some header files elsewhere? Joel, re compiler, I am using vs2005. The case I really need is 1... so I need to detect the compile-time static constant, and not a variable member... so is there a way to do it? Rds, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of Mathias Gaunard > Sent: 29 July 2009 13:12 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member >I can't find BOOST_HAS_STATIC_MEMBER_DATA in introspection in the sandbox. >Were you referring to some header files elsewhere? >Joel, re compiler, I am using vs2005. The case I really need is 1... so I need to detect the compile-time static constant, and not a variable member... so is there a way to do it? Rds, ---------------- I just realized the current Boost.Introspection in sandbox is different from the version I downloaded weeks ago. I had (has_member_data.hpp has_member_function.hpp traits.hpp). Now I see there are different files (introspection.hpp detail.hpp detail/*) from https://svn.boost.org/svn/boost/sandbox/introspection/boost/introspection/ Nevertheless, I still couldn't figure out how to detect the static const size_t member. Which version to use? Rds, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberHicham Mouline wrote:
> Nevertheless, I still couldn't figure out how to detect the static const > size_t member. > > Which version to use? No version allows this at the moment. You may, however, try to simply duplicate HAS_STATIC_MEMBER (or whatever it's called), change &X::Name to X::Name, and Type* to Type. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t member> -----Original Message-----
> From: boost-users-bounces@... [mailto:boost-users- > bounces@...] On Behalf Of Mathias Gaunard > Sent: 29 July 2009 15:48 > To: boost-users@... > Subject: Re: [Boost-users] detect if a type has a size_t member > > Hicham Mouline wrote: > > > Nevertheless, I still couldn't figure out how to detect the static const > > size_t member. > > > > Which version to use? > > No version allows this at the moment. > You may, however, try to simply duplicate HAS_STATIC_MEMBER (or whatever > it's called), change &X::Name to X::Name, and Type* to Type. Thanks very much, It worked for me on vs2005 and g++4.3.3 http://codepad.org/wsNi21Pr at least for the cases I wanted, that is struct S1 { static const size_t maxsize= 5; }; struct S5 { }; Nevertheless, it failed to compile on g++4.3.3 for struct S2 { static size_t maxsize; }; because of this error: error: 'S2::maxsize' is not a valid template argument for type 'long unsigned int' because it is a non-constant expression but compiled on vs2005 and failed ( which I don't care about ) thanks again, _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberAMDG
Mathias Gaunard wrote: > Because static const <integral type> = <some value> members are quite > special beasts. > Indeed, unlike other static members, you can't take their address, > since they don't exist in memory but only as compile-time constants. Yes you can take the address of a static const integral type. If you do, you are required to have a namespace scope definition, just like an ordinary member, but failure to do so, can only cause a linker error. It won't affect the compiler. In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: detect if a type has a size_t memberOn 7/29/09, Mathias Gaunard <mathias.gaunard@...> wrote:
> Because static const <integral type> = <some value> members are quite > special beasts. May be that's why in "The C++ Programming Language, 3ed", Bjarne says about them, "I consider this a misfeature. When you need a symbolic constant within a class declaration, use an enumerator." Regards, -Asif _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
| Free embeddable forum powered by Nabble | Forum Help |