From 6413c47d9807f318dffe9348485b9a8fcbc3542d Mon Sep 17 00:00:00 2001 From: Arkadiy Vertleyb Date: Wed, 10 Nov 2004 03:35:59 +0000 Subject: [PATCH] initial commit [SVN r2349] --- .../boost/typeof/compliant/concatenate.hpp | 67 ++++ .../boost/typeof/compliant/encode_decode.hpp | 28 ++ .../boost/typeof/compliant/int_encoding.hpp | 89 +++++ include/boost/typeof/compliant/limit_size.hpp | 35 ++ .../boost/typeof/compliant/lvalue_typeof.hpp | 54 +++ include/boost/typeof/compliant/modifiers.hpp | 118 +++++++ .../compliant/pointers_data_members.hpp | 44 +++ .../compliant/register_functions_iterate.hpp | 43 +++ .../compliant/register_mem_functions.hpp | 30 ++ .../typeof/compliant/template_encoding.hpp | 182 ++++++++++ .../boost/typeof/compliant/type_encoding.hpp | 26 ++ .../boost/typeof/compliant/typeof_impl.hpp | 62 ++++ include/boost/typeof/config.hpp | 26 ++ .../typeof/increment_registration_group.hpp | 21 ++ include/boost/typeof/register_functions.hpp | 51 +++ include/boost/typeof/register_fundamental.hpp | 25 ++ include/boost/typeof/typeof.hpp | 83 +++++ test/compliant/main.cpp | 323 ++++++++++++++++++ test/compliant/odr.hpp | 48 +++ test/compliant/odr1.cpp | 18 + test/compliant/odr2.cpp | 18 + test/compliant/typeid.hpp | 33 ++ test/compliant/typeof.sln | 21 ++ test/compliant/typeof.vcproj | 217 ++++++++++++ test/compliant/typeof_g++.bat | 2 + 25 files changed, 1664 insertions(+) create mode 100755 include/boost/typeof/compliant/concatenate.hpp create mode 100755 include/boost/typeof/compliant/encode_decode.hpp create mode 100755 include/boost/typeof/compliant/int_encoding.hpp create mode 100755 include/boost/typeof/compliant/limit_size.hpp create mode 100755 include/boost/typeof/compliant/lvalue_typeof.hpp create mode 100755 include/boost/typeof/compliant/modifiers.hpp create mode 100755 include/boost/typeof/compliant/pointers_data_members.hpp create mode 100755 include/boost/typeof/compliant/register_functions_iterate.hpp create mode 100755 include/boost/typeof/compliant/register_mem_functions.hpp create mode 100755 include/boost/typeof/compliant/template_encoding.hpp create mode 100755 include/boost/typeof/compliant/type_encoding.hpp create mode 100755 include/boost/typeof/compliant/typeof_impl.hpp create mode 100755 include/boost/typeof/config.hpp create mode 100755 include/boost/typeof/increment_registration_group.hpp create mode 100755 include/boost/typeof/register_functions.hpp create mode 100755 include/boost/typeof/register_fundamental.hpp create mode 100755 include/boost/typeof/typeof.hpp create mode 100755 test/compliant/main.cpp create mode 100755 test/compliant/odr.hpp create mode 100755 test/compliant/odr1.cpp create mode 100755 test/compliant/odr2.cpp create mode 100755 test/compliant/typeid.hpp create mode 100755 test/compliant/typeof.sln create mode 100755 test/compliant/typeof.vcproj create mode 100755 test/compliant/typeof_g++.bat diff --git a/include/boost/typeof/compliant/concatenate.hpp b/include/boost/typeof/compliant/concatenate.hpp new file mode 100755 index 0000000..7e6ec44 --- /dev/null +++ b/include/boost/typeof/compliant/concatenate.hpp @@ -0,0 +1,67 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_CONCATENATE_HPP_INCLUDED +#define BOOST_TYPEOF_CONCATENATE_HPP_INCLUDED + +#include +#include + +#include +#include +#include +#include +#include + +// Assumes iter0 contains initial iterator + +#define BOOST_TYPEOF_DECODE_PARAM(z, n, text) \ + typedef decode_type decode##n; \ + typedef typename decode##n::type p##n; \ + typedef typename decode##n::iter BOOST_PP_CAT(iter, BOOST_PP_INC(n)); + +#define BOOST_TYPEOF_DECODE_PARAMS(n)\ + BOOST_PP_REPEAT(n, BOOST_TYPEOF_DECODE_PARAM, BOOST_PP_EMPTY()); + +// The P0, P1, ... PN are encoded and added to V + +#define BOOST_TYPEOF_ENCODE_PARAMS_BEGIN(z, n, text)\ + typename encode_type< + +#define BOOST_TYPEOF_ENCODE_PARAMS_END(z, n, text)\ + , BOOST_PP_CAT(P, n)>::type + +#define BOOST_TYPEOF_ENCODE_PARAMS(n, ID) \ + BOOST_PP_REPEAT(n, BOOST_TYPEOF_ENCODE_PARAMS_BEGIN, BOOST_PP_EMPTY()) \ + typename BOOST_TYPEOF_PUSH_BACK >::type \ + BOOST_PP_REPEAT(n, BOOST_TYPEOF_ENCODE_PARAMS_END, BOOST_PP_EMPTY()) + +// constant-time push_back for mpl::vector +// to be removed once real one is available from MPL + +#define BOOST_TYPEOF_spec_push_back(z, i, text) \ + template \ + struct push_back, T> \ + { \ + typedef BOOST_PP_CAT(mpl::vector, BOOST_PP_INC(i))< \ + BOOST_PP_ENUM_PARAMS(i, T) BOOST_PP_COMMA_IF(i) T \ + > type; \ + }; \ + +#define BOOST_TYPEOF_implement_push_back() \ + template struct push_back; \ + BOOST_PP_REPEAT( \ + BOOST_TYPEOF_LIMIT_SIZE, \ + BOOST_TYPEOF_spec_push_back, \ + ~ \ + ) \ + +namespace boost{namespace type_of{namespace detail{ + BOOST_TYPEOF_implement_push_back(); +}}} + +#undef BOOST_TYPEOF_spec_push_back +#undef BOOST_TYPEOF_implement_push_back + +#endif//BOOST_TYPEOF_CONCATENATE_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/encode_decode.hpp b/include/boost/typeof/compliant/encode_decode.hpp new file mode 100755 index 0000000..a7dc7d2 --- /dev/null +++ b/include/boost/typeof/compliant/encode_decode.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_ENCODE_DECODE_HPP_INCLUDED +#define BOOST_TYPEOF_ENCODE_DECODE_HPP_INCLUDED + +namespace boost +{ + namespace type_of + { + namespace + { + template struct encode_type_impl; + template struct decode_type_impl; + } + + template struct encode_type + : encode_type_impl + {}; + + template struct decode_type + : decode_type_impl::type, typename mpl::next::type> + {}; + } +} + +#endif//BOOST_TYPEOF_ENCODE_DECODE_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/int_encoding.hpp b/include/boost/typeof/compliant/int_encoding.hpp new file mode 100755 index 0000000..264945d --- /dev/null +++ b/include/boost/typeof/compliant/int_encoding.hpp @@ -0,0 +1,89 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED +#define BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ + namespace type_of + { + template + struct split + { + static const size_t u = (size_t)n; + static const size_t value1 = (u >> 16) + 1; + static const size_t value2 = (u << 16 >> 16) + 1; + }; + + template + struct join + { + static const T value = (T)(((u1 - 1) << 16) + (u2 - 1)); + }; + + template + struct encode_long_integral + { + typedef + typename BOOST_TYPEOF_PUSH_BACK< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t::value1> >::type + , mpl::size_t::value2> >::type + type; + }; + + template + struct decode_long_integral + { + static const T value = join< + T, + mpl::deref::type::value, + mpl::deref::type>::type::value + >::value; + + typedef typename mpl::next::type>::type iter; + }; + + template + struct encode_short_integral + { + typedef + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t<(size_t)n + 1> >::type + type; + }; + + template + struct decode_short_integral + { + static const T value = (T)(mpl::deref::type::value - 1); + typedef typename mpl::next::type iter; + }; + + template + struct encode_integral : mpl::if_c< + (sizeof(T) < 4), + encode_short_integral, + encode_long_integral + >::type + {}; + + template + struct decode_integral : mpl::if_c< + (sizeof(T) < 4), + decode_short_integral, + decode_long_integral + >::type + {}; + } +}//namespace + +#endif//BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/limit_size.hpp b/include/boost/typeof/compliant/limit_size.hpp new file mode 100755 index 0000000..06701c8 --- /dev/null +++ b/include/boost/typeof/compliant/limit_size.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_LIMIT_SIZE_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_LIMIT_SIZE_HPP_INCLUDED + +#include "boost/mpl/vector.hpp" +#include "boost/mpl/aux_/config/ctps.hpp" +#include "boost/preprocessor/iterate.hpp" +#include "boost/preprocessor/if.hpp" +#include "boost/config.hpp" + +#ifndef BOOST_TYPEOF_LIMIT_SIZE +#define BOOST_TYPEOF_LIMIT_SIZE 50 +#endif//BOOST_TYPEOF_LIMIT_SIZE + +#if (BOOST_TYPEOF_LIMIT_SIZE > BOOST_MPL_LIMIT_VECTOR_SIZE) + +namespace boost +{ + namespace mpl + { + #define BOOST_PP_ITERATION_PARAMS_1 (3,( \ + BOOST_PP_INC(BOOST_MPL_LIMIT_VECTOR_SIZE), \ + BOOST_TYPEOF_LIMIT_SIZE, \ + "boost/mpl/vector/aux_/numbered.hpp")) + + #include BOOST_PP_ITERATE() + } +} + +#endif//BOOST_TYPEOF_LIMIT_SIZE > BOOST_MPL_LIMIT_VECTOR_SIZE + +#endif//BOOST_TYPEOF_COMPLIANT_LIMIT_SIZE_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/lvalue_typeof.hpp b/include/boost/typeof/compliant/lvalue_typeof.hpp new file mode 100755 index 0000000..4583ce7 --- /dev/null +++ b/include/boost/typeof/compliant/lvalue_typeof.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_LVALUE_TYPEOF_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_LVALUE_TYPEOF_HPP_INCLUDED + +#include + +namespace boost +{ + namespace type_of + { + enum + { + RVALUE = 1, + LVALUE, + CONST_LVALUE + }; + + char(&classify_expression(...))[ + RVALUE + ]; + + template + char(&classify_expression(T&))[ + is_const::value ? CONST_LVALUE : LVALUE + ]; + + template struct decorate_type + { + typedef T type; + }; + template struct decorate_type + { + typedef T& type; + }; + template struct decorate_type + { + typedef const T& type; + }; + } +} + +// Since this is always a type, +// just add "typename" when using in templates + +#define BOOST_LVALUE_TYPEOF(expr) \ + boost::type_of::decorate_type< \ + BOOST_TYPEOF(expr), \ + sizeof(boost::type_of::classify_expression(expr)) \ + >::type + +#endif//BOOST_TYPEOF_COMPLIANT_LVALUE_TYPEOF_HPP_INCLUDED \ No newline at end of file diff --git a/include/boost/typeof/compliant/modifiers.hpp b/include/boost/typeof/compliant/modifiers.hpp new file mode 100755 index 0000000..23628fb --- /dev/null +++ b/include/boost/typeof/compliant/modifiers.hpp @@ -0,0 +1,118 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_MODIFIERS_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_MODIFIERS_HPP_INCLUDED + +#include +#include + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +namespace boost +{ + namespace type_of + { + namespace + { + enum + { + CONST_ID = BOOST_TYPEOF_UNIQUE_ID(), + PTR_ID, + REF_ID, + ARRAY_ID, + CONST_ARRAY_ID + }; + + template struct encode_type_impl + { + typedef + typename encode_type< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t >::type + , T>::type + type; + }; + template struct decode_type_impl, Iter> + { + typedef decode_type d1; + typedef const typename d1::type type; + typedef typename d1::iter iter; + }; + template struct encode_type_impl + { + typedef + typename encode_type< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t >::type + , T>::type + type; + }; + template struct decode_type_impl, Iter> + { + typedef decode_type d1; + typedef typename d1::type* type; + typedef typename d1::iter iter; + }; + template struct encode_type_impl + { + typedef + typename encode_type< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t >::type + , T>::type + type; + }; + template struct decode_type_impl, Iter> + { + typedef decode_type d1; + typedef typename d1::type& type; + typedef typename d1::iter iter; + }; + template struct encode_type_impl + { + typedef + typename encode_type< + typename BOOST_TYPEOF_PUSH_BACK< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t >::type + , mpl::size_t >::type + , T>::type + type; + }; + template struct decode_type_impl, Iter> + { + enum{n = mpl::deref::type::value}; + typedef decode_type::type> d; + typedef typename d::type type[n]; + typedef typename d::iter iter; + }; + template struct encode_type_impl + { + typedef + typename encode_type< + typename BOOST_TYPEOF_PUSH_BACK< + typename BOOST_TYPEOF_PUSH_BACK< + V + , mpl::size_t >::type + , mpl::size_t >::type + , T>::type + type; + }; + template struct decode_type_impl, Iter> + { + enum{n = mpl::deref::type::value}; + typedef decode_type::type> d; + typedef typename d::type const type[n]; + typedef typename d::iter iter; + }; + } + } +} + +#endif//BOOST_TYPEOF_COMPLIANT_MODIFIERS_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/pointers_data_members.hpp b/include/boost/typeof/compliant/pointers_data_members.hpp new file mode 100755 index 0000000..2ec7589 --- /dev/null +++ b/include/boost/typeof/compliant/pointers_data_members.hpp @@ -0,0 +1,44 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_POINTERS_DATA_MEMBERS_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_POINTERS_DATA_MEMBERS_HPP_INCLUDED + +#include +#include + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +namespace boost +{ + namespace type_of + { + namespace + { + enum {PTR_DATA_MEM_ID = BOOST_TYPEOF_UNIQUE_ID()}; + + template + struct encode_type_impl + { + typedef BOOST_TYPEOF_ENCODE_PARAMS(2, PTR_DATA_MEM_ID) type; + }; + + template + struct decode_type_impl, Iter> + { + typedef Iter iter0; + BOOST_TYPEOF_DECODE_PARAMS(2) + + template struct workaround{ + typedef p0 T::* type; + }; + + typedef typename workaround::type type; + typedef iter2 iter; + }; + } + } +} + +#endif//BOOST_TYPEOF_COMPLIANT_POINTERS_DATA_MEMBERS_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/register_functions_iterate.hpp b/include/boost/typeof/compliant/register_functions_iterate.hpp new file mode 100755 index 0000000..3742ed0 --- /dev/null +++ b/include/boost/typeof/compliant/register_functions_iterate.hpp @@ -0,0 +1,43 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#define n BOOST_PP_ITERATION() + +// functions + +template +struct encode_type_impl +{ + typedef R BOOST_PP_CAT(P, n); + typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_ID + n) type; +}; + +template +struct decode_type_impl, Iter> +{ + typedef Iter iter0; + BOOST_TYPEOF_DECODE_PARAMS(BOOST_PP_INC(n)) + typedef BOOST_PP_CAT(p, n)(*type)(BOOST_PP_ENUM_PARAMS(n, p)); + typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter; +}; + +// member functions + +#define BOOST_TYPEOF_qualifier +#define BOOST_TYPEOF_id MEM_FUN_ID +#include + +#define BOOST_TYPEOF_qualifier const +#define BOOST_TYPEOF_id CONST_MEM_FUN_ID +#include + +#define BOOST_TYPEOF_qualifier volatile +#define BOOST_TYPEOF_id VOLATILE_MEM_FUN_ID +#include + +#define BOOST_TYPEOF_qualifier volatile const +#define BOOST_TYPEOF_id VOLATILE_CONST_MEM_FUN_ID +#include + +#undef n diff --git a/include/boost/typeof/compliant/register_mem_functions.hpp b/include/boost/typeof/compliant/register_mem_functions.hpp new file mode 100755 index 0000000..f1d3f64 --- /dev/null +++ b/include/boost/typeof/compliant/register_mem_functions.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +// member functions + +template +struct encode_type_impl +{ + typedef R BOOST_PP_CAT(P, n); + typedef T BOOST_PP_CAT(P, BOOST_PP_INC(n)); + typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_ADD(n, 2), BOOST_TYPEOF_id + n) type; +}; + +template +struct decode_type_impl, Iter> +{ + typedef Iter iter0; + BOOST_TYPEOF_DECODE_PARAMS(BOOST_PP_ADD(n, 2)) + template struct workaround{ + typedef BOOST_PP_CAT(p, n)(T::*type)(BOOST_PP_ENUM_PARAMS(n, p)) BOOST_TYPEOF_qualifier; + }; + typedef typename workaround::type type; + typedef BOOST_PP_CAT(iter, BOOST_PP_ADD(n, 2)) iter; +}; + +// undef parameters + +#undef BOOST_TYPEOF_id +#undef BOOST_TYPEOF_qualifier diff --git a/include/boost/typeof/compliant/template_encoding.hpp b/include/boost/typeof/compliant/template_encoding.hpp new file mode 100755 index 0000000..286dc87 --- /dev/null +++ b/include/boost/typeof/compliant/template_encoding.hpp @@ -0,0 +1,182 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_TEMPLATE_ENCODING_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_TEMPLATE_ENCODING_HPP_INCLUDED + +#include +#include + +#include +#include +#include + +////////// + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_class_ BOOST_TYPEOF_REGISTER_TEMPLATE_typename_ +#define BOOST_TYPEOF_REGISTER_TEMPLATE_typename_ (typename) (void) (TYPE) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_integral(x) (x) (x) (VALUE) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_RESULT_TYPE(x) typename x::type +#define BOOST_TYPEOF_REGISTER_TEMPLATE_RESULT_VALUE(x) x::value + +////////// + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_char_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(char) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_short_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(short) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_int_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(int) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_long_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(long) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_bool_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(bool) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_unsigned_ BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedchar BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned char) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedshort BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned short) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedint BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned int) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedlong BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned long) + +////////// + +#define BOOST_TYPEOF_TO_SEQ(tokens) BOOST_TYPEOF_ ## tokens ## _BOOST_TYPEOF + +#define BOOST_TYPEOF_unsigned (unsigned) + +#define BOOST_TYPEOF_char_BOOST_TYPEOF (char)(_) +#define BOOST_TYPEOF_short_BOOST_TYPEOF (short)(_) +#define BOOST_TYPEOF_int_BOOST_TYPEOF (int)(_) +#define BOOST_TYPEOF_long_BOOST_TYPEOF (long)(_) +#define BOOST_TYPEOF_bool_BOOST_TYPEOF (bool)(_) +#define BOOST_TYPEOF_class_BOOST_TYPEOF (class)(_) +#define BOOST_TYPEOF_typename_BOOST_TYPEOF (typename)(_) +#define BOOST_TYPEOF_unsigned_BOOST_TYPEOF (unsigned)(_) + +#define char_BOOST_TYPEOF (char) +#define short_BOOST_TYPEOF (short) +#define int_BOOST_TYPEOF (int) +#define long_BOOST_TYPEOF (long) + +#define EAT_SPACE(tokens) BOOST_PP_CAT(BOOST_PP_SEQ_ELEM(0, BOOST_TYPEOF_TO_SEQ(tokens)), BOOST_PP_SEQ_ELEM(1, BOOST_TYPEOF_TO_SEQ(tokens))) + +/////////// + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_DESCR(n, Params)\ + BOOST_PP_CAT(BOOST_TYPEOF_REGISTER_TEMPLATE_, EAT_SPACE(BOOST_PP_SEQ_ELEM(n, Params))) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_TYPE(n, Params)\ + BOOST_PP_SEQ_ELEM(0, BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_DESCR(n, Params)) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_SPEC_TYPE(n, Params)\ + BOOST_PP_SEQ_ELEM(1, BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_DESCR(n, Params)) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_RESULT(n, Params)\ + BOOST_PP_CAT(\ + BOOST_TYPEOF_REGISTER_TEMPLATE_RESULT_,\ + BOOST_PP_SEQ_ELEM(2, BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_DESCR(n, Params))\ + ) + +////////// + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_PAIR(z, n, Params)\ + BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_TYPE(n, Params) BOOST_PP_CAT(P, n) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_ENCODE_PARAM(z, n, Params)\ + typedef typename encode_dispatcher<\ + BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_SPEC_TYPE(n, Params)\ + >::encode::type BOOST_PP_CAT(V, BOOST_PP_INC(n)); + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_DECODE_PARAM(z, n, Params)\ + typedef encode_dispatcher<\ + BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_SPEC_TYPE(n, Params)\ + >::decode BOOST_PP_CAT(d, BOOST_PP_INC(n));\ + typedef typename BOOST_PP_CAT(d, BOOST_PP_INC(n))::iter BOOST_PP_CAT(iter, BOOST_PP_INC(n)); + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_DECODE_PARAM_RESULT(z, n, Params)\ + BOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_RESULT(n, Params)(BOOST_PP_CAT(d, BOOST_PP_INC(n))) + +////////// + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_X_IMPL(Name, Params, ID)\ + namespace boost{namespace type_of{namespace{\ + template\ + struct encode_type_impl >\ + {\ + typedef typename BOOST_TYPEOF_PUSH_BACK >::type V0;\ + BOOST_PP_REPEAT(\ + BOOST_PP_SEQ_SIZE(Params),\ + BOOST_TYPEOF_REGISTER_TEMPLATE_ENCODE_PARAM,\ + Params)\ + typedef BOOST_PP_CAT(V, BOOST_PP_SEQ_SIZE(Params)) type;\ + };\ + template\ + struct decode_type_impl, Iter>\ + {\ + typedef Iter iter0;\ + BOOST_PP_REPEAT(\ + BOOST_PP_SEQ_SIZE(Params),\ + BOOST_TYPEOF_REGISTER_TEMPLATE_DECODE_PARAM,\ + Params)\ + typedef Name<\ + BOOST_PP_ENUM(\ + BOOST_PP_SEQ_SIZE(Params),\ + BOOST_TYPEOF_REGISTER_TEMPLATE_DECODE_PARAM_RESULT,\ + Params)\ + > type;\ + typedef BOOST_PP_CAT(iter, BOOST_PP_SEQ_SIZE(Params)) iter;\ + };\ + }}} + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_X(Name, Params)\ + BOOST_TYPEOF_REGISTER_TEMPLATE_X_IMPL(Name, Params, BOOST_TYPEOF_UNIQUE_ID()) + +////////// + +#define BOOST_TYPEOF_spec_integral_dispatcher(r, data, T) \ + template<> struct encode_dispatcher \ + { \ + template \ + struct encode : encode_integral \ + {}; \ + template \ + struct decode : decode_integral \ + {}; \ + }; + +namespace boost +{ + namespace type_of + { + template struct encode_dispatcher + { + template + struct encode : encode_type + {}; + template + struct decode : decode_type + {}; + }; + + BOOST_PP_SEQ_FOR_EACH(BOOST_TYPEOF_spec_integral_dispatcher, ~, + (char) + (short) + (int) + (long) + (bool) + (unsigned char) + (unsigned short) + (unsigned int) + (unsigned long) + ) + } +} + +#undef BOOST_TYPEOF_spec_integral_dispatcher + +#endif//BOOST_TYPEOF_COMPLIANT_TEMPLATE_ENCODING_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/type_encoding.hpp b/include/boost/typeof/compliant/type_encoding.hpp new file mode 100755 index 0000000..60c930e --- /dev/null +++ b/include/boost/typeof/compliant/type_encoding.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_TYPE_ENCODING_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_TYPE_ENCODING_HPP_INCLUDED + +#include + +#define BOOST_TYPEOF_REGISTER_TYPE_IMPL(T, Id) \ + \ + template struct encode_type_impl \ + : BOOST_TYPEOF_PUSH_BACK > \ + {}; \ + template struct decode_type_impl, Iter> \ + { \ + typedef T type; \ + typedef Iter iter; \ + }; + +#define BOOST_TYPEOF_REGISTER_TYPE(Type) \ + namespace boost{namespace type_of{namespace{ \ + BOOST_TYPEOF_REGISTER_TYPE_IMPL(Type, BOOST_TYPEOF_UNIQUE_ID()) \ + }}} + +#endif//BOOST_TYPEOF_COMPLIANT_TYPE_ENCODING_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/typeof_impl.hpp b/include/boost/typeof/compliant/typeof_impl.hpp new file mode 100755 index 0000000..fe17fa2 --- /dev/null +++ b/include/boost/typeof/compliant/typeof_impl.hpp @@ -0,0 +1,62 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED +#define BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include + +#define BOOST_TYPEOF_PUSH_BACK detail::push_back +//#define BOOST_TYPEOF_PUSH_BACK mpl::push_back + +#include +#include + +namespace boost +{ + namespace type_of + { + template + char(&at(const T&))[ + mpl::at, T>::type, mpl::size_t >::type::value + ]; + + template + char(&size(const T&))[ + mpl::size, T>::type>::value + ]; + } +} + +#define BOOST_TYPEOF_AT(n, expr) sizeof(boost::type_of::at(expr)) +#define BOOST_TYPEOF_SIZE(expr) sizeof(boost::type_of::size(expr)) + +#define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ + boost::mpl::size_t + +#define BOOST_TYPEOF(Expr) \ + boost::type_of::decode_type< \ + boost::mpl::begin< \ + BOOST_PP_CAT(boost::mpl::vector, BOOST_TYPEOF_LIMIT_SIZE)< \ + BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ + > \ + >::type \ + >::type + +#define BOOST_TYPEOF_TPL(Expr) \ + typename boost::type_of::decode_type< \ + typename boost::mpl::begin< \ + BOOST_PP_CAT(boost::mpl::vector, BOOST_TYPEOF_LIMIT_SIZE)< \ + BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ + > \ + >::type \ + >::type + +#endif//BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED diff --git a/include/boost/typeof/config.hpp b/include/boost/typeof/config.hpp new file mode 100755 index 0000000..9916a0e --- /dev/null +++ b/include/boost/typeof/config.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_CONFIG_HPP_INCLUDED +#define BOOST_TYPEOF_CONFIG_HPP_INCLUDED + +#if !defined(BOOST_TYPEOF_COMPLIANT) && !defined(BOOST_TYPEOF_VINTAGE) && !defined(BOOST_TYPEOF_NATIVE) + +# if defined __GNUC__ +# define BOOST_TYPEOF_NATIVE + +# elif defined __MWERKS__ +# define BOOST_TYPEOF_NATIVE + +# elif defined BOOST_TYPEOF_NO_PARTIAL_TEMPLATE_SPECIALIZATION +# define BOOST_TYPEOF_VINTAGE + +# else +# define BOOST_TYPEOF_COMPLIANT + +# endif + +#endif + +#endif//BOOST_TYPEOF_CONFIG_HPP_INCLUDED diff --git a/include/boost/typeof/increment_registration_group.hpp b/include/boost/typeof/increment_registration_group.hpp new file mode 100755 index 0000000..0509e1a --- /dev/null +++ b/include/boost/typeof/increment_registration_group.hpp @@ -0,0 +1,21 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +// Inclusion of this file increments BOOST_TYPEOF_REGISTRATION_GROUP +// This method was suggested by Paul Mensonides + +#ifndef BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP_HPP_INCLUDED + +# define BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP_HPP_INCLUDED +# include +# define BOOST_TYPEOF_REGISTRATION_GROUP 0 + +#else + +# define BOOST_PP_VALUE BOOST_TYPEOF_REGISTRATION_GROUP + 1 +# include BOOST_PP_ASSIGN_SLOT(1) +# undef BOOST_TYPEOF_REGISTRATION_GROUP +# define BOOST_TYPEOF_REGISTRATION_GROUP BOOST_PP_SLOT(1) + +#endif//BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP_HPP_INCLUDED diff --git a/include/boost/typeof/register_functions.hpp b/include/boost/typeof/register_functions.hpp new file mode 100755 index 0000000..f763d11 --- /dev/null +++ b/include/boost/typeof/register_functions.hpp @@ -0,0 +1,51 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_REGISTER_FUNCTIONS_HPP_INCLUDED +#define BOOST_TYPEOF_REGISTER_FUNCTIONS_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +#ifndef BOOST_TYPEOF_FUN_PARAMS_SUPPORTED +#define BOOST_TYPEOF_FUN_PARAMS_SUPPORTED 10 +#endif + +enum +{ + FUN_ID = BOOST_TYPEOF_UNIQUE_ID(), + VOID_FUN_ID = FUN_ID + 1 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + MEM_FUN_ID = FUN_ID + 2 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + CONST_MEM_FUN_ID = FUN_ID + 3 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + VOID_MEM_FUN_ID = FUN_ID + 4 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + CONST_VOID_MEM_FUN_ID = FUN_ID + 5 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + VOLATILE_MEM_FUN_ID = FUN_ID + 6 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + VOLATILE_CONST_MEM_FUN_ID = FUN_ID + 7 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + VOLATILE_VOID_MEM_FUN_ID = FUN_ID + 8 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED), + VOLATILE_CONST_VOID_MEM_FUN_ID = FUN_ID + 9 * BOOST_PP_INC(BOOST_TYPEOF_FUN_PARAMS_SUPPORTED) +}; + +namespace boost +{ + namespace type_of + { + namespace + { + # define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPEOF_FUN_PARAMS_SUPPORTED) + // BOOST_PP_FILENAME_1 is defined outside + # include BOOST_PP_ITERATE() + } + } +} + +#endif//BOOST_TYPEOF_REGISTER_FUNCTIONS_HPP_INCLUDED diff --git a/include/boost/typeof/register_fundamental.hpp b/include/boost/typeof/register_fundamental.hpp new file mode 100755 index 0000000..208163b --- /dev/null +++ b/include/boost/typeof/register_fundamental.hpp @@ -0,0 +1,25 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_REGISTER_FUNDAMENTAL_HPP_INCLUDED +#define BOOST_TYPEOF_REGISTER_FUNDAMENTAL_HPP_INCLUDED + +#include + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +BOOST_TYPEOF_REGISTER_TYPE(char); +BOOST_TYPEOF_REGISTER_TYPE(short); +BOOST_TYPEOF_REGISTER_TYPE(int); +BOOST_TYPEOF_REGISTER_TYPE(long); +BOOST_TYPEOF_REGISTER_TYPE(unsigned char); +BOOST_TYPEOF_REGISTER_TYPE(unsigned short); +BOOST_TYPEOF_REGISTER_TYPE(unsigned int); +BOOST_TYPEOF_REGISTER_TYPE(unsigned long); +BOOST_TYPEOF_REGISTER_TYPE(float); +BOOST_TYPEOF_REGISTER_TYPE(double); +BOOST_TYPEOF_REGISTER_TYPE(bool); +BOOST_TYPEOF_REGISTER_TYPE(void); + +#endif//BOOST_TYPEOF_REGISTER_FUNDAMENTAL_HPP_INCLUDED diff --git a/include/boost/typeof/typeof.hpp b/include/boost/typeof/typeof.hpp new file mode 100755 index 0000000..0d68b34 --- /dev/null +++ b/include/boost/typeof/typeof.hpp @@ -0,0 +1,83 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_TYPEOF_HPP_INCLUDED +#define BOOST_TYPEOF_TYPEOF_HPP_INCLUDED + +// implementation + +#include + +// BOOST_TYPEOF, BOOST_TYPEOF_TPL + +#if defined(BOOST_TYPEOF_COMPLIANT) +# include + +#elif defined(BOOST_TYPEOF_VINTAGE) +// include something to define BOOST_TYPEOF, BOOST_TYPEOF_TPL + +#else//BOOST_TYPEOF_NATIVE + +# if !defined BOOST_TYPEOF +# define BOOST_TYPEOF __typeof__ +# endif +# define BOOST_TYPEOF_TPL BOOST_TYPEOF + +#endif + +// auto + +#define BOOST_AUTO(Var, Expr) BOOST_TYPEOF(Expr) Var(Expr) +#define BOOST_AUTO_TPL(Var, Expr) BOOST_TYPEOF_TPL(Expr) Var(Expr) + +// lvalue typeof + +#if defined(BOOST_TYPEOF_VINTAGE) +// include lvalue_typeof definition +#else +# include +#endif + +// type/template encoding + +#if defined(BOOST_TYPEOF_COMPLIANT) +# include +# include +#elif defined(BOOST_TYPEOF_VINTAGE) +// include type encoding definitions +#else//BOOST_TYPEOF_NATIVE +# define BOOST_TYPEOF_REGISTER_TYPE(x) +# define BOOST_TYPEOF_REGISTER_TEMPLATE_X(x, params) +#endif + +#define BOOST_TYPEOF_REGISTER_TEMPLATE_TYPE_PARAM_(z, n, data) (typename) + +#define BOOST_TYPEOF_REGISTER_TEMPLATE(Name, n)\ + BOOST_TYPEOF_REGISTER_TEMPLATE_X(Name,\ + BOOST_PP_REPEAT(n, BOOST_TYPEOF_REGISTER_TEMPLATE_TYPE_PARAM_, ~)\ + ) + +#define BOOST_TYPEOF_UNIQUE_ID()\ + BOOST_TYPEOF_REGISTRATION_GROUP * 0x10000 + __LINE__ + +#define BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()\ + + +// register stuff + +#include + +#if defined(BOOST_TYPEOF_COMPLIANT) + +# include +# include +# define BOOST_PP_FILENAME_1 +# include + +#elif defined(BOOST_TYPEOF_VINTAGE) +// include stuff here +#else //BOOST_TYPEOF_NATIVE +#endif + +#endif//BOOST_TYPEOF_TYPEOF_HPP_INCLUDED \ No newline at end of file diff --git a/test/compliant/main.cpp b/test/compliant/main.cpp new file mode 100755 index 0000000..ff98783 --- /dev/null +++ b/test/compliant/main.cpp @@ -0,0 +1,323 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#pragma message("including typeof.hpp...") +#include +#pragma message("done") + +#include +#include + +#pragma message("registering") +#include "stl/register.hpp" +#include "mpl/register.hpp" +#include "spirit/register.hpp" +#include "lambda/register.hpp" +#pragma message("done") + +#include +#include +#include + +#include +#include +#include +#include "typeid.hpp" + +using namespace std; + +#pragma message("started") + +double f_0() +{ + cout << "functions with no params" << endl; + return 0; +} +double f_9(int, double, short, char*, bool, char, float, long, unsigned short) +{ + cout << "functions with 9 params" << endl; + return 0; +} +void vf_0() +{ + cout << "void functions with 0 params" << endl; +} +void vf_9(int, double, short, char*, bool, char, float, long, unsigned short) +{ + cout << "void functions with 9 params" << endl; +} + +struct x +{ + int f_0() volatile + { + cout << "member functions with no params" << endl; + return 0; + } + int f_9(int, double, char, int, double, char, int, double, char) + { + cout << "member functions with 9 params" << endl; + return 0; + } + void vf_0() + { + cout << "void member functions with no params" << endl; + } + void vf_9(int, double, char, int, double, char, int, double, char) + { + cout << "void member functions with 9 params" << endl; + } + int cf_0() const volatile + { + cout << "const member functions with no params" << endl; + return 0; + } + int cf_9(int, double, char, int, double, char, int, double, char) const + { + cout << "const member functions with 9 params" << endl; + return 0; + } + void cvf_0() const + { + cout << "const void member functions with no params" << endl; + } + void cvf_9(int, double, char, int, double, char, int, double, char) const + { + cout << "const void member functions with 9 params" << endl; + } + static void sf_0() + { + cout << "static member function" << endl; + } + std::vector m_v; +}; + +struct noncop : boost::noncopyable +{}; +const noncop& foo_nc() +{ + static noncop nc; + return nc; +} + +template struct with_integrals +{}; + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +BOOST_TYPEOF_REGISTER_TYPE(x) +BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals, + (class) + (char) + (unsigned short) + (int) + (unsigned long) + (bool) + (bool) + (unsigned) + ); + +BOOST_TYPEOF_REGISTER_TYPE(noncop) + +main() +{ +//#pragma message("integral...") +// { +// with_integrals expr; +// BOOST_AUTO(v, expr); +// v; +// with_integrals expr1; +// BOOST_AUTO(v1, expr1); +// v1; +// } +#pragma message("Noncopyable...") + { + //BOOST_AUTO(v, foo_nc()); + BOOST_AUTO(const& v, foo_nc()); + } +#pragma message("Lvalue preserving...") + { + int n; + const int cn = 0; + int& rn = n; + const int& rcn = cn; + int f(); + //const int cf(); + int& rf(); + const int& rcf(); + + cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + //cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + cout << type_id::name() << endl; + + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + //BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + } +#pragma message("compiling Lambda example...") + { + using namespace boost::lambda; + + BOOST_AUTO(fun, _1 > 15 && _2 < 20); + int n = 19; + assert(fun(n, n)); + + std::cout << typeid(fun).name() << std::endl; + } +#pragma message("compiling Spirit example...") + { + // spirit example + + using namespace boost::spirit; + using namespace boost::lambda; + using namespace std; + + vector v; + + BOOST_AUTO(parser, + (real_p[push_back_a(v)] >> *(',' >> real_p[push_back_a(v)])) + ); + + parse("3.14159, 2.71828", parser, space_p); + + for_each(v.begin(), v.end(), cout << _1 << ' '); + cout << endl; + } +#pragma message("compiling another Spirit example...") + { + // more spirit... + + using namespace boost::spirit; + + BOOST_AUTO( + skipper, + ( space_p + | "//" >> *(anychar_p - '\n') >> '\n' + | "/*" >> *(anychar_p - "*/") >> "*/" + ) + ); + + bool success = parse( + "/*this is a comment*/\n//this is a c++ comment\n\n", + *skipper).full; + + assert(success); + } +#pragma message("compiling Modifiers example...") + { + //modifiers + + using namespace std; + using namespace boost; + + // top-level pointers are preserved... + + mpl::vector3* foo(); + cout << typeid(BOOST_TYPEOF(foo())).name() << endl; + + // ... but top-level refs are not :( + + mpl::vector2& bar(); + cout << typeid(BOOST_TYPEOF(bar())).name() << endl; + + mpl::vector1 vi; + cout << "int[5]" << endl; + cout << typeid(BOOST_TYPEOF(vi)).name() << endl; + + mpl::vector1 vci; + cout << "const int[5]" << endl; + cout << typeid(BOOST_TYPEOF(vci)).name() << endl; + } +#pragma message("compiling functions example...") + { + BOOST_AUTO(p0, &f_0); + (*p0)(); + + BOOST_AUTO(p9, &f_9); + (*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling void functions example...") + { + BOOST_AUTO(p0, &vf_0); + (*p0)(); + + BOOST_AUTO(p9, &vf_9); + (*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling member functions example...") + { + x xx; + + BOOST_AUTO(p0, &x::f_0); + (xx.*p0)(); + + BOOST_AUTO(p9, &x::f_9); + (xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling void member functions example...") + { + x xx; + + BOOST_AUTO(p0, &x::vf_0); + (xx.*p0)(); + + BOOST_AUTO(p9, &x::vf_9); + (xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling const member functions example...") + { + x xx; + + BOOST_AUTO(p0, &x::cf_0); + (xx.*p0)(); + + BOOST_AUTO(p9, &x::cf_9); + (xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling const void member functions example...") + { + x xx; + + BOOST_AUTO(p0, &x::cvf_0); + (xx.*p0)(); + + BOOST_AUTO(p9, &x::cvf_9); + (xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0); + } +#pragma message("compiling static member functions example...") + { + BOOST_AUTO(p0, &x::sf_0); + (*p0)(); + } +#pragma message("pointers to data members...") + { + BOOST_AUTO(p, &x::m_v); + x xx; + (xx.*p).push_back(1); + } +#pragma message("ODR") + + void odr_test1(); + void odr_test2(); + odr_test1(); + odr_test2(); + +#pragma message("done!") +} + diff --git a/test/compliant/odr.hpp b/test/compliant/odr.hpp new file mode 100755 index 0000000..d37fb34 --- /dev/null +++ b/test/compliant/odr.hpp @@ -0,0 +1,48 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef ODR_HPP_INCLUDED +#define ODR_HPP_INCLUDED + +#include + +void odr_test1(); +void odr_test2(); + +// trying to cause ODR violation in a class template + +template +class sum_t +{ +public: + typedef BOOST_TYPEOF_TPL(T() + U()) result_type; + + sum_t(const T& t, const U& u) + : m_sum(t + u) + {} + BOOST_TYPEOF_TPL(T() + U()) operator()() + { + BOOST_AUTO_TPL(result, m_sum); + return result; + } +private: + BOOST_TYPEOF_TPL(T() + U()) m_sum; +}; + +template +sum_t make_sum(const T& t, const U& u) +{ + return sum_t(t, u); +} + +// trying to cause ODR violation in a function template + +template +typename sum_t::result_type sum(const T& t, const U& u) +{ + BOOST_AUTO_TPL(result, t + u); + return result; +} + +#endif//ODR_HPP_INCLUDED diff --git a/test/compliant/odr1.cpp b/test/compliant/odr1.cpp new file mode 100755 index 0000000..82eece3 --- /dev/null +++ b/test/compliant/odr1.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#include +#include "odr.hpp" + +using namespace std; + +void odr_test1() +{ + char i = 5; + double d = 3.14; + cout << sum(d, i) << endl; + cout << sum(i, d) << endl; + cout << make_sum(d, i)() << endl; + cout << make_sum(i, d)() << endl; +} diff --git a/test/compliant/odr2.cpp b/test/compliant/odr2.cpp new file mode 100755 index 0000000..31b4bdd --- /dev/null +++ b/test/compliant/odr2.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#include +#include "odr.hpp" + +using namespace std; + +void odr_test2() +{ + char i = 5; + double d = 3.14; + cout << sum(d, i) << endl; + cout << sum(i, d) << endl; + cout << make_sum(d, i)() << endl; + cout << make_sum(i, d)() << endl; +} diff --git a/test/compliant/typeid.hpp b/test/compliant/typeid.hpp new file mode 100755 index 0000000..9dc0587 --- /dev/null +++ b/test/compliant/typeid.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef TYPEID_HPP_INCLUDED +#define TYPEID_HPP_INCLUDED + +#include + +template struct type_id +{ + static std::string name() + { + return typeid(T).name(); + } +}; +template struct type_id +{ + static std::string name() + { + return type_id::name() + "&"; + } +}; +template struct type_id +{ + static std::string name() + { + return std::string("const ") + type_id::name(); + } +}; + +#endif//TYPEID_HPP_INCLUDED + diff --git a/test/compliant/typeof.sln b/test/compliant/typeof.sln new file mode 100755 index 0000000..25b339b --- /dev/null +++ b/test/compliant/typeof.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "typeof", "typeof.vcproj", "{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Debug.ActiveCfg = Debug|Win32 + {5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Debug.Build.0 = Debug|Win32 + {5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Release.ActiveCfg = Release|Win32 + {5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/test/compliant/typeof.vcproj b/test/compliant/typeof.vcproj new file mode 100755 index 0000000..e0742c6 --- /dev/null +++ b/test/compliant/typeof.vcproj @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/compliant/typeof_g++.bat b/test/compliant/typeof_g++.bat new file mode 100755 index 0000000..714a5fb --- /dev/null +++ b/test/compliant/typeof_g++.bat @@ -0,0 +1,2 @@ +g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. -D BOOST_TYPEOF_FORCE_EMULATION -D BOOST_TYPEOF_LIMIT_SIZE=50 -D BOOST_MPL_LIMIT_VECTOR_SIZE=50 odr1.cpp odr2.cpp main.cpp +g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. odr1.cpp odr2.cpp main.cpp