gcc 4.8.1&clang 3.3,c ++ 11功能完整,我需要在构造make_shared/c ++ 14 make_unique等元素的函数中转发args.但我有类型扣除/转发初始化列表/数组的问题
我需要工作的例子foo * foo3{ make_it<foo>( {{1,1},{ 10,10 }}, 10 ) };,因此std::initializer_list将推断它的参数和函数将转发它们
#include <initializer_list>
#include <algorithm>
struct foo
{
struct pairs{ int a,b; };
foo( int value ){}
foo( std::initializer_list<pairs> elems, int value ){}
};
//some custom allocation mechanizm
char store[sizeof(foo)*2];
char * store_ptr = &store[0];
void * allocfromstore( size_t sz ) { void * ret = store_ptr; store_ptr+= sz; return ret; }
template<typename ValueType, typename ArrType, typename... Args>
ValueType …Run Code Online (Sandbox Code Playgroud) 我只是好奇为什么用using指令设计它.对于1)struct被视为命名空间和2)它不是:
struct foo
{
using type0 = int;
};
namespace bar
{
using type1 = int;
}
using bar::type1;
using type0 = foo::type0; // 1)
using foo::type0; // 2)
Run Code Online (Sandbox Code Playgroud)
clang version 3.3 (branches/release_33 186829)
clang -std=c++11 test.cpp
test.cpp:13:12: error: using declaration can not refer to class member
using foo::type0;
Run Code Online (Sandbox Code Playgroud)
gcc version 4.8.1
c++ -std=c++11 test.cpp
test.cpp:13:12: error: ‘foo’ is not a namespace
using foo::type0;
Run Code Online (Sandbox Code Playgroud)