11constexprfunctionsuserecursionratherthaniteration//(C++14constexprfunctionsmayuselocalvariablesandloops)constexprintfactorial(intn){returnn
size_tN>constexprconststr(constchar(&a)[N]):p(a),sz(N-1){}constexprcharoperator[](std::size_tn)const{returnn
::list<int>l={1,100,2,3,10,1,11,-1,12};l.remove(1);//removebothelementsequalto1l.remove_if([](intn){returnn
forward_list<int>l={1,100,2,3,10,1,11,-1,12};l.remove(1);//removebothelementsequalto1l.remove_if([](intn){returnn
staticautoconstexprget(std::pair<T,U>const&pair)->typenamestd::tuple_element<N,decltype(pair)>::type{returnN
returna+b;}};namespacestd{template<>structis_bind_expression<MyBind>:publictrue_type{};}intf(intn1,intn2){returnn1
namespacestd{template<>structis_placeholder<My_2>:publicintegral_constant<int,2>{};}intf(intn1,intn2){returnn1
template<classT>structidentity{usingtype=T;};//OK:equivalentdeclarationtemplate<classV>VX::good(Vn){returnn
;//Error:nisnotinscopeinclassbodystaticconstintn=1;intx[n];//OK:nisnowinscopeinclassbody};intX::g(){returnn
Initializewithdefaultvalues0,1,2,3,4fromalambdafunction//Equivalenttostd::iota(v.begin(),v.end(),0);intn={0};std::generate(v.begin(),v.end(),[&n]{returnn
classTriple{statictriple(n){if(n===undefined){n=1;}returnn*3;}}classBiggerTripleextendsTriple{statictriple
vector>intmain(){std::vector<int>v{0,0,3,0,2,4,5,0,7};std::stable_partition(v.begin(),v.end(),[](intn){returnn
`i-n``It``Ittemp=i;returntemp-=n;``b-a``difference_type``returnn;`Precondition: 有一个值n类型difference_type
根据值的类型,_.iteratee将返回: //Novalue_.iteratee();=>_.identity()//Function_.iteratee(function(n){returnn*2;
unboundfunctionexpressioncallbackfoo(function(){returnthis.a;});//OK//recursivenamedfunctioncallbackfoo(functionbar(n){returnn
5,7,4,2,8,6,1,9,0,3};std::replace_copy_if(v.begin(),v.end(),std::ostream_iterator<int>(std::cout,""),[](intn){returnn
conststd::pair<int,int>∓//referencemember};voidfoo(int){}structA{};structB:A{intn;operatorint&(){returnn