forked from boostorg/type_traits
Add new versions of decay, extent, function_traits.
This commit is contained in:
42
include/boost/type_traits/decay.hpp
Normal file
42
include/boost/type_traits/decay.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// (C) Copyright John Maddock & Thorsten Ottosen 2005.
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt).
|
||||
//
|
||||
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
|
||||
|
||||
|
||||
#ifndef BOOST_TT_DECAY_HPP_INCLUDED
|
||||
#define BOOST_TT_DECAY_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/is_array.hpp>
|
||||
#include <boost/type_traits/is_function.hpp>
|
||||
#include <boost/type_traits/remove_bounds.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <class T, bool Array, bool Function> struct decay_imp { typedef T type; };
|
||||
template <class T> struct decay_imp<T, true, false> { typedef typename remove_bounds<T>::type* type; };
|
||||
template <class T> struct decay_imp<T, false, true> { typedef T* type; };
|
||||
|
||||
}
|
||||
|
||||
template< class T >
|
||||
struct decay
|
||||
{
|
||||
private:
|
||||
typedef typename remove_reference<T>::type Ty;
|
||||
public:
|
||||
typedef typename detail::decay_imp<T, boost::is_array<T>::value, boost::is_function<T>::value>::type type;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_TT_DECAY_HPP_INCLUDED
|
137
include/boost/type_traits/extent.hpp
Normal file
137
include/boost/type_traits/extent.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt).
|
||||
//
|
||||
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
|
||||
|
||||
|
||||
#ifndef BOOST_TT_EXTENT_HPP_INCLUDED
|
||||
#define BOOST_TT_EXTENT_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail{
|
||||
|
||||
#if defined( __CODEGEARC__ )
|
||||
// wrap the impl as main trait provides additional MPL lambda support
|
||||
template < typename T, std::size_t N >
|
||||
struct extent_imp {
|
||||
static const std::size_t value = __array_extent(T, N);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template <class T, std::size_t N>
|
||||
struct extent_imp
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
#if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
|
||||
template <class T, std::size_t R, std::size_t N>
|
||||
struct extent_imp<T[R], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
|
||||
template <class T, std::size_t R, std::size_t N>
|
||||
struct extent_imp<T const[R], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
|
||||
template <class T, std::size_t R, std::size_t N>
|
||||
struct extent_imp<T volatile[R], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
|
||||
template <class T, std::size_t R, std::size_t N>
|
||||
struct extent_imp<T const volatile[R], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
|
||||
template <class T, std::size_t R>
|
||||
struct extent_imp<T[R],0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = R);
|
||||
};
|
||||
|
||||
template <class T, std::size_t R>
|
||||
struct extent_imp<T const[R], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = R);
|
||||
};
|
||||
|
||||
template <class T, std::size_t R>
|
||||
struct extent_imp<T volatile[R], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = R);
|
||||
};
|
||||
|
||||
template <class T, std::size_t R>
|
||||
struct extent_imp<T const volatile[R], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = R);
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && !defined(__IBMCPP__) && !BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840)) && !defined(__MWERKS__)
|
||||
template <class T, std::size_t N>
|
||||
struct extent_imp<T[], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
template <class T, std::size_t N>
|
||||
struct extent_imp<T const[], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
template <class T, std::size_t N>
|
||||
struct extent_imp<T volatile[], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
template <class T, std::size_t N>
|
||||
struct extent_imp<T const volatile[], N>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = (::boost::detail::extent_imp<T, N-1>::value));
|
||||
};
|
||||
template <class T>
|
||||
struct extent_imp<T[], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
template <class T>
|
||||
struct extent_imp<T const[], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
template <class T>
|
||||
struct extent_imp<T volatile[], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
template <class T>
|
||||
struct extent_imp<T const volatile[], 0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // non-CodeGear implementation
|
||||
} // ::boost::detail
|
||||
|
||||
template <class T, std::size_t N = 0>
|
||||
struct extent
|
||||
: public ::boost::integral_constant<std::size_t, ::boost::detail::extent_imp<T,N>::value>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_TT_IS_MEMBER_FUNCTION_POINTER_HPP_INCLUDED
|
20
include/boost/type_traits/floating_point_promotion.hpp
Normal file
20
include/boost/type_traits/floating_point_promotion.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2005 Alexander Nasonov.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef FILE_boost_type_traits_floating_point_promotion_hpp_INCLUDED
|
||||
#define FILE_boost_type_traits_floating_point_promotion_hpp_INCLUDED
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T> struct floating_point_promotion { typedef T type; };
|
||||
template<> struct floating_point_promotion<float> { typedef double type; };
|
||||
template<> struct floating_point_promotion<float const> { typedef double const type; };
|
||||
template<> struct floating_point_promotion<float volatile>{ typedef double volatile type; };
|
||||
template<> struct floating_point_promotion<float const volatile> { typedef double const volatile type; };
|
||||
|
||||
}
|
||||
|
||||
#endif // #ifndef FILE_boost_type_traits_floating_point_promotion_hpp_INCLUDED
|
||||
|
174
include/boost/type_traits/function_traits.hpp
Normal file
174
include/boost/type_traits/function_traits.hpp
Normal file
@@ -0,0 +1,174 @@
|
||||
|
||||
// Copyright 2000 John Maddock (john@johnmaddock.co.uk)
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt).
|
||||
//
|
||||
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
|
||||
|
||||
#ifndef BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
|
||||
#define BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/type_traits/is_function.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename Function> struct function_traits_helper;
|
||||
|
||||
template<typename R>
|
||||
struct function_traits_helper<R (*)(void)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 0);
|
||||
typedef R result_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1>
|
||||
struct function_traits_helper<R (*)(T1)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 1);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T1 argument_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2>
|
||||
struct function_traits_helper<R (*)(T1, T2)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 2);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T1 first_argument_type;
|
||||
typedef T2 second_argument_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 3);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 4);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 5);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 6);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
typedef T6 arg6_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 7);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
typedef T6 arg6_type;
|
||||
typedef T7 arg7_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 8);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
typedef T6 arg6_type;
|
||||
typedef T7 arg7_type;
|
||||
typedef T8 arg8_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 9);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
typedef T6 arg6_type;
|
||||
typedef T7 arg7_type;
|
||||
typedef T8 arg8_type;
|
||||
typedef T9 arg9_type;
|
||||
};
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8, typename T9,
|
||||
typename T10>
|
||||
struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(unsigned, arity = 10);
|
||||
typedef R result_type;
|
||||
typedef T1 arg1_type;
|
||||
typedef T2 arg2_type;
|
||||
typedef T3 arg3_type;
|
||||
typedef T4 arg4_type;
|
||||
typedef T5 arg5_type;
|
||||
typedef T6 arg6_type;
|
||||
typedef T7 arg7_type;
|
||||
typedef T8 arg8_type;
|
||||
typedef T9 arg9_type;
|
||||
typedef T10 arg10_type;
|
||||
};
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
template<typename Function>
|
||||
struct function_traits :
|
||||
public boost::detail::function_traits_helper<typename boost::add_pointer<Function>::type>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
|
127
test/decay_test.cpp
Normal file
127
test/decay_test.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
|
||||
// (C) Copyright John Maddock & Thorsten Ottosen 2005.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_integral_constant.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/decay.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#ifdef BOOST_INTEL
|
||||
// remark #383: value copied to temporary, reference to temporary used
|
||||
// std::pair<std::string, int> p2 = boost::make_pair( "foo", 1 );
|
||||
// ^
|
||||
#pragma warning(disable:383)
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
int proc1()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int proc2(int c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
//
|
||||
// An almost optimal version of std::make_pair()
|
||||
//
|
||||
template< class F, class S >
|
||||
inline std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type,
|
||||
BOOST_DEDUCED_TYPENAME tt::decay<const S>::type >
|
||||
make_pair( const F& f, const S& s )
|
||||
{
|
||||
return std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type,
|
||||
BOOST_DEDUCED_TYPENAME tt::decay<const S>::type >( f, s );
|
||||
}
|
||||
|
||||
/*
|
||||
This overload will mess up vc7.1
|
||||
|
||||
template< class F, class S >
|
||||
inline std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type,
|
||||
BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type >
|
||||
make_pair( F& f, S& s )
|
||||
{
|
||||
return std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type,
|
||||
BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type >( f, s );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
TT_TEST_BEGIN(is_class)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<int>::type,int>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<char[2]>::type,char*>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<char[2][3]>::type,char(*)[3]>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<const char[2]>::type,const char*>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<wchar_t[2]>::type,wchar_t*>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value),
|
||||
true );
|
||||
|
||||
typedef int f1_type(void);
|
||||
typedef int f2_type(int);
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<f1_type>::type,int (*)(void)>::value),
|
||||
true );
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<
|
||||
::tt::decay<f2_type>::type,int (*)(int)>::value),
|
||||
true );
|
||||
|
||||
std::pair<std::string,std::string> p = boost::make_pair( "foo", "bar" );
|
||||
std::pair<std::string, int> p2 = boost::make_pair( "foo", 1 );
|
||||
#ifndef BOOST_NO_STD_WSTRING
|
||||
std::pair<std::wstring,std::string> p3 = boost::make_pair( L"foo", "bar" );
|
||||
std::pair<std::wstring, int> p4 = boost::make_pair( L"foo", 1 );
|
||||
#endif
|
||||
|
||||
//
|
||||
// Todo: make these work sometime. The test id not directly
|
||||
// related to decay<T>::type and can be avoided for now.
|
||||
//
|
||||
/*
|
||||
int array[10];
|
||||
std::pair<int*,int*> p5 = boost::make_pair( array, array );
|
||||
#ifndef __BORLANDC__
|
||||
std::pair<int(*)(void), int(*)(int)> p6 = boost::make_pair(boost::proc1, boost::proc2);
|
||||
p6.first();
|
||||
p6.second(1);
|
||||
#endif
|
||||
*/
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
49
test/extent_test.cpp
Normal file
49
test/extent_test.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_integral_constant.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/extent.hpp>
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(extent)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int[]>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int[][10]>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int[5][10]>::value, 5);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int[5][10][40]>::value, 5);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int (&)[5][10]>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int (*)[5][10]>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int,1>::value), 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[],1>::value), 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[][10],1>::value), 10);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[5][10],1>::value), 10);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[5][10][40],1>::value), 10);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int (&)[5][10],1>::value), 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int (*)[5][10],1>::value), 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[5][10],2>::value), 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[5][10][40],2>::value), 40);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::extent<int[5][10][40],3>::value), 0);
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int*>::value, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int&>::value, 0);
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::extent<int&&>::value, 0);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
68
test/function_traits_test.cpp
Normal file
68
test/function_traits_test.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_type.hpp"
|
||||
#include "check_integral_constant.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/function_traits.hpp>
|
||||
#endif
|
||||
|
||||
typedef void(pf_zero1)();
|
||||
typedef int(pf_zero2)();
|
||||
typedef const int& (pf_zero3)();
|
||||
typedef void(pf_one1)(int);
|
||||
typedef int(pf_one2)(int);
|
||||
typedef const int&(pf_one3)(const int&);
|
||||
typedef void(pf_two1)(int,int);
|
||||
typedef int(pf_two2)(int,int);
|
||||
typedef const int&(pf_two3)(const int&,const int&);
|
||||
|
||||
|
||||
TT_TEST_BEGIN(function_traits)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero1>::arity, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero2>::arity, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero3>::arity, 0);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one1>::arity, 1);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one2>::arity, 1);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one3>::arity, 1);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two1>::arity, 2);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two2>::arity, 2);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two3>::arity, 2);
|
||||
|
||||
BOOST_CHECK_TYPE(void, ::tt::function_traits<pf_zero1>::result_type);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_zero2>::result_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_zero3>::result_type, const int&);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one1>::result_type, void);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one2>::result_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one3>::result_type, const int&);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::result_type, void);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::result_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::result_type, const int&);
|
||||
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one1>::arg1_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one2>::arg1_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_one3>::arg1_type, const int&);
|
||||
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::arg1_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::arg1_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::arg1_type, const int&);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::arg2_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::arg2_type, int);
|
||||
BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::arg2_type, const int&);
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user