我正在尝试创建部分专用模板,如果传递了一个,则进一步专门化 std::unique_ptr
template <typename T, typename = void>
struct Foo;
// A
template <typename T>
struct Foo<std::unique_ptr<T>, typename std::enable_if<std::is_class<T>::value>::type> {...};
// B
template <typename T>
struct Foo<T, typename std::enable_if<std::is_class<T>::value>::type> {...};
void fn() {
Foo<std::unique_ptr<T>> foo;
}
Run Code Online (Sandbox Code Playgroud)
我的理解是A比B更专业,应该是使用的.但至少在MSVC 2015中我得到了错误:
error C2752: 'Foo<FieldT,void>': more than one partial specialization matches the template argument list
Run Code Online (Sandbox Code Playgroud)
这里有什么我想念的吗?
我希望有两个项目构建相同的源文件,第二个项目只有一个小子集,以及一些不同的定义和构建标志.
当我尝试这样的事情时:
SET (this_target PROJECT1)
PROJECT(${this_target})
...
ADD_EXECUTABLE(#{this_target} ...)
SET (this_target PROJECT2)
PROJECT(${this_target})
...
add_definitions (-DMYDEFINE)
TARGET_LINK_LIBRARIES( ${this_target} -myflag )
ADD_EXECUTABLE(#{this_target} ...)
Run Code Online (Sandbox Code Playgroud)
它最终创建了两个项目,看似正确的源文件等,但由于某些原因,至少在Visual Studio 2010中,两个项目似乎都在链接器标志中定义了MYDEFINE和myflag.
我不确定为什么它似乎适用于文件,但不是标志.