Boost-pp: how to determine if a macro parameter is a tuple -


a tuple comma-separated list enclosed parens, e.g.

() (,) (thing,) (2,3) 

if have

#define istuple(x) \\... 

i'd istuple(nope) resolve 0 , istuple((yep)) resolve 1.

[fwiw, have _rtfm_'d plenty.]

it done in preprocessing library little work, variadic macro data library (added boost since question posted) has ready-made solution. boost_vmd_is_tuple, defined in boost/vmd/is_tuple.hpp, should you're looking for:

#include <iostream>  #include <boost/vmd/is_tuple.hpp>  #if boost_vmd_is_tuple() != 0   #error boost_vmd_is_tuple() != 0 #endif  #if boost_vmd_is_tuple(nope) != 0   #error boost_vmd_is_tuple(nope) != 0 #endif  #if boost_vmd_is_tuple((yep)) != 1   #error boost_vmd_is_tuple((yep)) != 1 #endif  #if boost_vmd_is_tuple(()) != 1   #error boost_vmd_is_tuple(()) != 1 #endif  #if boost_vmd_is_tuple((,)) != 1   #error boost_vmd_is_tuple((,)) != 1 #endif  #if boost_vmd_is_tuple((thing,)) != 1   #error boost_vmd_is_tuple((thing,)) != 1 #endif  #if boost_vmd_is_tuple((2,3)) != 1   #error boost_vmd_is_tuple((2,3)) != 1 #endif  static_assert(boost_vmd_is_tuple() == 0,"boost_vmd_is_tuple() != 0"); static_assert(boost_vmd_is_tuple(nope) == 0,"boost_vmd_is_tuple(nope) != 0"); static_assert(boost_vmd_is_tuple((yep)) == 1,"boost_vmd_is_tuple((yep)) != 1"); static_assert(boost_vmd_is_tuple(()) == 1,"boost_vmd_is_tuple(()) != 1"); static_assert(boost_vmd_is_tuple((,)) == 1,"boost_vmd_is_tuple((,)) != 1"); static_assert(boost_vmd_is_tuple((thing,)) == 1,"boost_vmd_is_tuple((thing,)) != 1"); static_assert(boost_vmd_is_tuple((2,3)) == 1,"boost_vmd_is_tuple((2,3)) != 1");  int main(void) {     using std::cout;     using std::endl;     cout << "boost_vmd_is_tuple() == " << boost_vmd_is_tuple() << endl;     cout << "boost_vmd_is_tuple(nope) == " << boost_vmd_is_tuple(nope) << endl;     cout << "boost_vmd_is_tuple((yep)) == " << boost_vmd_is_tuple((yep)) << endl;     cout << "boost_vmd_is_tuple(()) == " << boost_vmd_is_tuple(()) << endl;     cout << "boost_vmd_is_tuple((,)) == " << boost_vmd_is_tuple((,)) << endl;     cout << "boost_vmd_is_tuple((thing,)) == " << boost_vmd_is_tuple((thing,)) << endl;     cout << "boost_vmd_is_tuple((2,3)) == " << boost_vmd_is_tuple((2,3)) << endl;      return 0; } 

output:

boost_vmd_is_tuple() == 0 boost_vmd_is_tuple(nope) == 0 boost_vmd_is_tuple((yep)) == 1 boost_vmd_is_tuple(()) == 1 boost_vmd_is_tuple((,)) == 1 boost_vmd_is_tuple((thing,)) == 1 boost_vmd_is_tuple((2,3)) == 1 

(http://coliru.stacked-crooked.com/a/6e41eaf17437c5d5)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -