In C ++ 0x you have template typedeffinally got it!
: ...
:
template< typename second>
using TypedefName = SomeType<OtherType, second, 5>;
template <class Type>
using vector3 = vector<Type, 3>;
, ;)
. , , . , static_assert .
.
template <class Type, size_t Size>
class vector
{
public:
template <class... Args>
vector(Args... args): data({args...})
{
// Necessary only if you wish to ensure that the exact number of args
// is passed, otherwise there could be less than requested
BOOST_MPL_ASSERT_RELATION(sizeof...(Args), ==, Size);
}
private:
T data[Size];
};
, , boost::enable_if.
template <class Type, size_t Size>
class vector
{
public:
vector(Type a0, typename boost::enable_if_c< Size == 1 >::type* = 0);
vector(Type a0, Type a1, typename boost::enable_if_c< Size == 2 >::type* = 0);
// ...
};
Boost.Preprocessor .
BOOST_PP_REPEAT(MAX_COUNT, CONSTRUCTOR_MACRO, ~);
#define CONSTRUCTOR_MACRO(z, n, data) \
vector( \
BOOST_PP_ENUM_PARAMS(n, Type a), \
typename boost::enable_if_c< Size == n >::type* = 0 \
);
. BOOST_PP_REPEAT.
, , , .