_TPL-related fixes

[SVN r2613]
This commit is contained in:
Arkadiy Vertleyb
2005-06-08 02:57:29 +00:00
parent bd6c0e07c4
commit cdc03862c9
5 changed files with 82 additions and 15 deletions

View File

@@ -76,11 +76,36 @@ namespace boost
// Since this is always a type,
// just add "typename" when using in templates
#ifndef BOOST_TYPEOF_COMPLIANT
#define BOOST_LVALUE_TYPEOF(expr) \
boost::type_of::decorate_type< \
BOOST_TYPEOF(expr), \
sizeof(*boost::type_of::classify_expression(expr)) \
>::type
#else //BOOST_TYPEOF_COMPLIANT
#include <boost/typeof/typeof_impl.hpp>
namespace boost { namespace type_of {
template<class V, int n>
struct decorate_decode_begin
{
typedef typename decorate_type<
typename decode_begin<V>::type,
n
>::type type;
};
}}
#define BOOST_LVALUE_TYPEOF(expr) \
boost::type_of::decorate_decode_begin< \
BOOST_TYPEOF_ENCODED_VECTOR(expr), \
sizeof(*boost::type_of::classify_expression(expr)) \
>::type
#endif
#endif//BOOST_TYPEOF_LVALUE_TYPEOF_HPP_INCLUDED

View File

@@ -30,10 +30,21 @@
# define BOOST_TYPEOF_TEXT "using native imlementation"
# include <boost/typeof/message.hpp>
# if !defined BOOST_TYPEOF
# define BOOST_TYPEOF __typeof__
# if !defined BOOST_TYPEOF_KEYWORD
# define BOOST_TYPEOF_KEYWORD __typeof__
# endif
/* Native __typeof__ can accept either type or value.
Something like "int()" can be viewed either way, but
__typeof__ consideres it a type. We force it otherwise
to ensure consistensy with emulation */
namespace boost { namespace type_of {
template<class T> T& ensure_obj(const T&);
}}
# define BOOST_TYPEOF(expr) BOOST_TYPEOF_KEYWORD(boost::type_of::ensure_obj(expr))
# define BOOST_TYPEOF_TPL BOOST_TYPEOF
#endif

View File

@@ -34,21 +34,26 @@ namespace boost { namespace type_of {
#undef BOOST_TYPEOF_sizer_item
namespace boost { namespace type_of {
template<class V>
struct decode_begin
{
typedef typename decode_type<typename V::begin>::type type;
};
}}
#define BOOST_TYPEOF_TYPEITEM(z, n, expr)\
boost::mpl::size_t<sizeof(boost::type_of::encode(expr).item ## n)>
#define BOOST_TYPEOF(Expr) \
boost::type_of::decode_type< \
BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \
BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \
>::begin \
>::type
#define BOOST_TYPEOF_ENCODED_VECTOR(Expr) \
BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \
BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \
>
#define BOOST_TYPEOF_TPL(Expr) \
typename boost::type_of::decode_type< \
typename BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \
BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \
>::begin \
>::type
#define BOOST_TYPEOF(Expr)\
boost::type_of::decode_begin<BOOST_TYPEOF_ENCODED_VECTOR(Expr) >::type
#define BOOST_TYPEOF_TPL typename BOOST_TYPEOF
#endif//BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED

View File

@@ -205,6 +205,27 @@ void lvalue_typeof_test()
//BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(21), int>::value)); //msvc
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(int(21)), int>::value));
}
namespace ltype
{
int& foo(double);
char foo(int);
template<class T>
struct result_type
{
typedef typename BOOST_LVALUE_TYPEOF(foo(T())) type;
};
BOOST_STATIC_ASSERT((boost::is_same<
result_type<int>::type,
char
>::value));
BOOST_STATIC_ASSERT((boost::is_same<
result_type<double>::type,
int&
>::value));
};
#define BOOST_TYPEOF_TEXT "Noncopyable..."
#include <boost/typeof/message.hpp>
@@ -331,6 +352,11 @@ void odr_test()
odr_test2();
}
#define BOOST_TYPEOF_TEXT "native/emulation consistency..."
#include <boost/typeof/message.hpp>
BOOST_STATIC_ASSERT((is_same<BOOST_TYPEOF(int()), int>::value));
#define BOOST_TYPEOF_TEXT "main()..."
#include <boost/typeof/message.hpp>

View File

@@ -37,7 +37,7 @@ void odr_test2();
template<class T, class U>
typename sum_t<T,U>::result_type sum_t<T,U>::operator()()
{
// BOOST_AUTO_TPL(result, m_sum);
//BOOST_AUTO_TPL(result, m_sum);
return m_sum;
}