相关疑难解决方法(0)

什么是std :: move(),什么时候应该使用?

  1. 它是什么?
  2. 它有什么作用?
  3. 什么时候应该使用?

赞赏良好的链接.

c++ c++-faq move-semantics c++11 stdmove

581
推荐指数
6
解决办法
24万
查看次数

带有std :: is_reference的std :: enable_if无法编译

就像std::reference_wrapper在封面下使用指针来存储"引用"一样,我试图用以下代码做类似的事情.

#include <type_traits>

struct Foo
{
    void* _ptr;

    template<typename T>
    Foo(T val,
        typename std::enable_if
            <
                std::is_reference<T>::value,
                void
            >::type* = nullptr)
        : _ptr(&val)
    { }
};

int main()
{
    int i = 0;
    int& l = i;

    Foo u2(l);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,这无法编译:

CXX main.cpp
main.cpp: In function ‘int main()’:
main.cpp:23:13: error: no matching function for call to ‘Foo::Foo(int&)’
main.cpp:23:13: note: candidates are:
main.cpp:8:5: note: template<class T> Foo::Foo(T, typename std::enable_if<std::is_reference<_Tp>::value, void>::type*)
main.cpp:8:5: note:   template argument deduction/substitution failed:
main.cpp: In …
Run Code Online (Sandbox Code Playgroud)

c++ type-traits enable-if c++11

3
推荐指数
1
解决办法
1034
查看次数

标签 统计

c++ ×2

c++11 ×2

c++-faq ×1

enable-if ×1

move-semantics ×1

stdmove ×1

type-traits ×1