From 38d97bae80a403ee5a7aa92f77df6eec29cf3319 Mon Sep 17 00:00:00 2001 From: Arkadiy Vertleyb Date: Wed, 17 Nov 2004 19:51:22 +0000 Subject: [PATCH] integration [SVN r2369] --- .../compliant/register_functions_iterate.hpp | 59 ++-- include/boost/typeof/register_functions.hpp | 9 +- include/boost/typeof/typeof.hpp | 5 +- test/compliant/main.cpp | 323 ------------------ test/compliant/test_compliant.cpp | 60 ++++ test/compliant/typeid.hpp | 33 -- test/compliant/typeof.vcproj | 9 +- test/compliant/typeof_g++.bat | 4 +- test/main.cpp | 139 ++++++++ test/{compliant => }/mpl/register.hpp | 0 test/{compliant => }/stl/register.hpp | 0 11 files changed, 244 insertions(+), 397 deletions(-) delete mode 100755 test/compliant/main.cpp create mode 100755 test/compliant/test_compliant.cpp delete mode 100755 test/compliant/typeid.hpp create mode 100755 test/main.cpp rename test/{compliant => }/mpl/register.hpp (100%) rename test/{compliant => }/stl/register.hpp (100%) diff --git a/include/boost/typeof/compliant/register_functions_iterate.hpp b/include/boost/typeof/compliant/register_functions_iterate.hpp index 3742ed0..78aecae 100755 --- a/include/boost/typeof/compliant/register_functions_iterate.hpp +++ b/include/boost/typeof/compliant/register_functions_iterate.hpp @@ -4,40 +4,43 @@ #define n BOOST_PP_ITERATION() -// functions - -template -struct encode_type_impl +namespace { - typedef R BOOST_PP_CAT(P, n); - typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_ID + n) type; -}; + // functions -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; -}; + 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; + }; -// member functions + 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; + }; -#define BOOST_TYPEOF_qualifier -#define BOOST_TYPEOF_id MEM_FUN_ID -#include + // member functions -#define BOOST_TYPEOF_qualifier const -#define BOOST_TYPEOF_id CONST_MEM_FUN_ID -#include + #define BOOST_TYPEOF_qualifier + #define BOOST_TYPEOF_id MEM_FUN_ID + #include -#define BOOST_TYPEOF_qualifier volatile -#define BOOST_TYPEOF_id VOLATILE_MEM_FUN_ID -#include + #define BOOST_TYPEOF_qualifier const + #define BOOST_TYPEOF_id CONST_MEM_FUN_ID + #include -#define BOOST_TYPEOF_qualifier volatile const -#define BOOST_TYPEOF_id VOLATILE_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/register_functions.hpp b/include/boost/typeof/register_functions.hpp index f116217..f97dd18 100755 --- a/include/boost/typeof/register_functions.hpp +++ b/include/boost/typeof/register_functions.hpp @@ -36,12 +36,9 @@ namespace boost { namespace type_of { - namespace - { - # define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPEOF_LIMIT_FUNCTION_ARITY) - // BOOST_PP_FILENAME_1 is defined outside - # include BOOST_PP_ITERATE() - } + # define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPEOF_LIMIT_FUNCTION_ARITY) + // BOOST_PP_FILENAME_1 is defined outside + # include BOOST_PP_ITERATE() } } diff --git a/include/boost/typeof/typeof.hpp b/include/boost/typeof/typeof.hpp index 37a7c33..54f7b5d 100755 --- a/include/boost/typeof/typeof.hpp +++ b/include/boost/typeof/typeof.hpp @@ -27,8 +27,9 @@ #endif // auto -#define BOOST_AUTO(Var, Expr) BOOST_TYPEOF(Expr) Var(Expr) -#define BOOST_AUTO_TPL(Var, Expr) BOOST_TYPEOF_TPL(Expr) Var(Expr) +#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) diff --git a/test/compliant/main.cpp b/test/compliant/main.cpp deleted file mode 100755 index 0ac213f..0000000 --- a/test/compliant/main.cpp +++ /dev/null @@ -1,323 +0,0 @@ -// 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/test_compliant.cpp b/test/compliant/test_compliant.cpp new file mode 100755 index 0000000..9428dae --- /dev/null +++ b/test/compliant/test_compliant.cpp @@ -0,0 +1,60 @@ +#include + +#include "spirit/register.hpp" +#include "lambda/register.hpp" +#include +#include +#include + +#pragma message("compiling Lambda example...") +void test_lambda() +{ + 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...") +void test_spirit1() +{ + 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...") +void test_spirit2() +{ + 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); +} + + diff --git a/test/compliant/typeid.hpp b/test/compliant/typeid.hpp deleted file mode 100755 index 9dc0587..0000000 --- a/test/compliant/typeid.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// 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.vcproj b/test/compliant/typeof.vcproj index e0742c6..7a14b04 100755 --- a/test/compliant/typeof.vcproj +++ b/test/compliant/typeof.vcproj @@ -115,7 +115,7 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + RelativePath="..\main.cpp"> @@ -123,6 +123,9 @@ + + + RelativePath="..\stl\register.hpp"> + RelativePath="..\mpl\register.hpp"> diff --git a/test/compliant/typeof_g++.bat b/test/compliant/typeof_g++.bat index da8cd48..c062d3e 100755 --- a/test/compliant/typeof_g++.bat +++ b/test/compliant/typeof_g++.bat @@ -1,2 +1,2 @@ -g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. -D BOOST_TYPEOF_COMPLIANT -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 +g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. -D BOOST_TYPEOF_COMPLIANT -D BOOST_TYPEOF_LIMIT_SIZE=50 -D BOOST_MPL_LIMIT_VECTOR_SIZE=50 odr1.cpp odr2.cpp test_compliant.cpp ..\main.cpp +g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. odr1.cpp odr2.cpp test_compliant.cpp ..\main.cpp diff --git a/test/main.cpp b/test/main.cpp new file mode 100755 index 0000000..6308fa5 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,139 @@ +// 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 +#include +#include +#include + +#include +#include +#include + +#include "stl/register.hpp" +#include "mpl/register.hpp" + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +using namespace std; + +template +struct typeof_test +{ + static T foo(); + enum {value = boost::is_same< + BOOST_TYPEOF_TPL(typeof_test::foo()), //fully qualify foo() to avoid problems with g++ + typename boost::remove_reference::type>::type + >::value}; +}; + +#pragma message("started") + +struct x +{}; + +BOOST_TYPEOF_REGISTER_TYPE(x); + +template struct with_integrals +{}; + +BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals, + (class) + (char) + (unsigned short) + (int) + (unsigned long) + (bool) + (bool) + (unsigned) + ); + +#pragma message("integral...") +BOOST_STATIC_ASSERT((typeof_test >::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); + +#pragma message("namespace-level functions...") +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); + +#pragma message("member functions...") +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +//BOOST_STATIC_ASSERT(typeof_test::value); + +#pragma message("data members...") +BOOST_STATIC_ASSERT(typeof_test::value); + +#pragma message("modifiers...") +BOOST_STATIC_ASSERT((typeof_test*>::value)); +BOOST_STATIC_ASSERT((typeof_test&>::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); + +#pragma message("Lvalue test...") +void lvalue_typeof_test() +{ + int n; + const int cn = 0; + int& rn = n; + const int& rcn = cn; + int f(); + //const int cf(); + int& rf(); + const int& rcf(); + + 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("Noncopyable...") + +BOOST_TYPEOF_REGISTER_TYPE(boost::noncopyable); + +struct noncopiable_test +{ + const boost::noncopyable& foo(); + void bar() + { + BOOST_AUTO(const& v, foo()); + } +}; + +#pragma message("ODR...") +void odr_test() +{ + void odr_test1(); + void odr_test2(); + odr_test1(); + odr_test2(); +} + +#pragma message("main()...") +main() +{ + odr_test(); +} + +#pragma message("done!") diff --git a/test/compliant/mpl/register.hpp b/test/mpl/register.hpp similarity index 100% rename from test/compliant/mpl/register.hpp rename to test/mpl/register.hpp diff --git a/test/compliant/stl/register.hpp b/test/stl/register.hpp similarity index 100% rename from test/compliant/stl/register.hpp rename to test/stl/register.hpp