Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 是否有一种方法可以将左值和右值列表转换为分别具有引用类型和完整类型的元组的元组?_C++11_Templates_Visual C++ - Fatal编程技术网

C++11 是否有一种方法可以将左值和右值列表转换为分别具有引用类型和完整类型的元组的元组?

C++11 是否有一种方法可以将左值和右值列表转换为分别具有引用类型和完整类型的元组的元组?,c++11,templates,visual-c++,C++11,Templates,Visual C++,这是问题的第二部分 我想基于参数列表的左值/右值类型创建一个元组(或元组对)元组。这就是我到目前为止所做的: #include <tuple> using LPCWSTR = wchar_t const*; namespace detail { template <typename T> struct VarVal : std::pair<LPCWSTR, T> { // Importing the base cons

这是问题的第二部分

我想基于参数列表的左值/右值类型创建一个元组(或元组对)元组。这就是我到目前为止所做的:

#include <tuple>
using LPCWSTR = wchar_t const*;

namespace detail
{
    template <typename T>
    struct VarVal : std::pair<LPCWSTR, T>
    {
        // Importing the base constructors so I don't have to redefine them
        using std::pair<LPCWSTR, T>::pair;
        VarVal(VarVal const&) = delete; // copy could be made valid, but I don't want it copied around.
        VarVal(VarVal&&) = default; // would rather that no copying/moving be done, but not sure how
    };
}

// lvalue
template <typename T>
detail::VarVal<std::reference_wrapper<T&>> vv(LPCWSTR var, T& val)
{
    return{ var, val };
}

// rvalue
template <typename T>
detail::VarVal<T const> vv(LPCWSTR var, T&& val)
{
    return{ var, val };
}

struct SomeType
{
    int x;
    auto GetLeft()   const { return  1; }
    auto& GetRight()  const { return  x; }
};

auto varvals(SomeType const& object)
{
    return make_tuple(
        vv( L"left",  object.GetLeft() ),
        vv( L"right", object.GetRight() )
    );
}
#包括
使用LPCWSTR=wchar_t const*;
名称空间详细信息
{
模板
结构VarVal:std::pair
{
//导入基本构造函数,这样我就不必重新定义它们了
使用std::pair::pair;
VarVal(VarVal const&)=delete;//可以使副本有效,但我不希望它被复制。
VarVal(VarVal&&)=default;//希望不进行复制/移动,但不确定如何进行
};
}
//左值
模板
详细信息::VarVal vv(LPCWSTR var,T&val)
{
返回{var,val};
}
//右值
模板
详细信息::VarVal vv(LPCWSTR var,T&&val)
{
返回{var,val};
}
结构类型
{
int x;
auto GetLeft()常量{return 1;}
auto&GetRight()常量{return x;}
};
自动变量(SomeType常量和对象)
{
返回make\u tuple(
vv(L“left”,object.GetLeft()),
vv(L“right”,object.GetRight())
);
}

这适用于右值,但当我将其用于左值时,它会说
reference\u wrapper要求T是对象类型或函数类型。

我错过了什么

我错过了什么

模板
详细信息::VarVal vv(LPCWSTR var,T&val)
{
返回{var,val};
}
std::reference\u wrapper
,而不是
std::reference\u wrapper

我错过了什么

模板
详细信息::VarVal vv(LPCWSTR var,T&val)
{
返回{var,val};
}

std::reference_wrapper
,而非
std::reference_wrapper

必须睡眠剥夺。谢谢,一定是睡眠不足。谢谢
template <typename T>
detail::VarVal<std::reference_wrapper<T>> vv(LPCWSTR var, T& val)
{
    return{ var, val };
}