相关疑难解决方法(0)

是否可以"存储"模板参数包而不扩展它?

当我偶然发现这个问题时,我正在尝试使用C++ 0x可变参数模板:

template < typename ...Args >
struct identities
{
    typedef Args type; //compile error: "parameter packs not expanded with '...'
};

//The following code just shows an example of potential use, but has no relation
//with what I am actually trying to achieve.
template < typename T >
struct convert_in_tuple
{
    typedef std::tuple< typename T::type... > type;
};

typedef convert_in_tuple< identities< int, float > >::type int_float_tuple;
Run Code Online (Sandbox Code Playgroud)

当我尝试输入模板参数包时,GCC 4.5.0给出了一个错误.

基本上,我想将参数包"存储"在typedef中,而无需解压缩.可能吗?如果没有,是否有一些理由不允许这样做?

c++ templates variadic-templates c++11

71
推荐指数
2
解决办法
2万
查看次数

C++ - 迭代元组和类型与常量参数的分辨率

我目前正在为元组编写算术运算符重载.运算符迭代元组以对其每个元素执行操作.这是operator + =的定义:

template< typename... Ts, std::size_t I = 0 >
inline typename std::enable_if< I == sizeof... (Ts), std::tuple< Ts... >& >::type operator +=(std::tuple< Ts... >& lhs, const std::tuple< Ts... >& rhs)
{
    return lhs;
}

template< typename... Ts, std::size_t I = 0 >
inline typename std::enable_if< I != sizeof... (Ts), std::tuple< Ts... >& >::type operator +=(std::tuple< Ts... >& lhs, const std::tuple< Ts... >& rhs)
{
    std::get< I >(lhs) += std::get< I >(rhs);
    return operator +=< Ts..., I + 1 …
Run Code Online (Sandbox Code Playgroud)

c++ tuples enable-if c++11

11
推荐指数
1
解决办法
6203
查看次数

标签 统计

c++ ×2

c++11 ×2

enable-if ×1

templates ×1

tuples ×1

variadic-templates ×1