c++ - Class locals as predicates pre C++11 -
the next code compiles without errors/warnings when beingness built c++11 mode, using gcc , clang. if effort compile without c++11 mode , error occurs in 2nd scope.
#include <algorithm> #include <vector> struct astruct { int v; }; struct astruct_cmp0 { bool operator()(const astruct& a0, const astruct& a1) { homecoming a0.v < a1.v; } }; int main() { std::vector<astruct> alist; { // works - no errors std::stable_sort(alist.begin(),alist.end(),astruct_cmp0()); } { struct astruct_cmp1 { bool operator()(const astruct& a0, const astruct& a1) { homecoming a0.v < a1.v; } }; // error: template argument uses local type 'astruct_cmp1' std::stable_sort(alist.begin(),alist.end(),astruct_cmp1()); } homecoming 0; }
my question is: c++11 alter allows local struct definition? please point me specific section in standard (section 9.8 perhaps?)
in c++03 function local types not viable template arguments. in c++11 function local types viable template arguments. key quote in c++03 14.3.1 [temp.arg.type] paragraph 2:
the next types shall not used template-argument template type-parameter:
a type name has no linkage ...in c++11 constraint removed.
the relevant section on when linkage defined 3.5 [basic.link] (in both standard) long , points entities without linkage exclusion, paragraph 8 in c++03:
names not covered these rules have no linkage. ...
types defined within function not listed in "these rules".
c++ c++11 compiler-errors language-lawyer predicate
No comments:
Post a Comment