Files
preprocessor/example/is_integral.cpp

36 lines
1.6 KiB
C++
Raw Normal View History

// Copyright (C) 2002
// Housemarque Oy
// http://www.housemarque.com
//
// Permission to copy, use, modify, sell and distribute this software is
// granted provided this copyright notice appears in all copies. This
// software is provided "as is" without express or implied warranty, and
// with no claim as to its suitability for any purpose.
// See http://www.boost.org for most recent version.
2002-01-29 12:24:55 +00:00
// This example demonstrates the usage of preprocessor lists for generating C++ code.
#include <boost/preprocessor/list/for_each.hpp>
#include <boost/preprocessor/tuple/to_list.hpp>
2002-01-29 12:24:55 +00:00
#include <boost/preprocessor/empty.hpp>
2002-01-29 12:24:55 +00:00
// List of integral types. (Strictly speaking, wchar_t should be on the list.)
#define INTEGRAL_TYPES\
2002-01-29 12:24:55 +00:00
BOOST_PP_TUPLE_TO_LIST(9,(char, signed char, unsigned char, short, unsigned short, int, unsigned, long, unsigned long))
2002-01-29 12:24:55 +00:00
// Template for testing whether a type is an integral type.
template<class T> struct is_integral {enum {value = false};};
2002-01-29 12:24:55 +00:00
// Macro for defining a specialization of is_integral<> template.
// NOTE: CV is invoked so that it is possible to pass empty cv-qualifiers.
#define IS_INTEGRAL_SPECIALIZATION(_,CV,T)\
template<> struct is_integral<CV() T> {enum {value = true};};
2002-01-29 12:24:55 +00:00
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, BOOST_PP_EMPTY, INTEGRAL_TYPES)
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, const BOOST_PP_EMPTY, INTEGRAL_TYPES)
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, volatile BOOST_PP_EMPTY, INTEGRAL_TYPES)
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, const volatile BOOST_PP_EMPTY, INTEGRAL_TYPES)
#undef IS_INTEGRAL_SPECIALIZATION
#undef INTEGRAL_TYPES