c++11 - C++ function returning function -


where in standard functions returning functions disallowed? understand conceptually ridiculous, seems me grammar allow them. according webpage, "noptr-declarator [is] valid declarator" include declarator of function:

int f()(); 

regarding syntax.

it seems me syntax, spelled out in [dcl.decl], allows

int f(char)(double) 

which interpreted the function f that takes a char and returns function same signature as int g(double).

1    declarator: 2       ptr-declarator 3       noptr-declarator parameters-and-qualifiers trailing-return-type 4    ptr-declarator: 5        noptr-declarator 6        ptr-operator ptr-declarator 7    noptr-declarator: 8        declarator-id attribute-specifier-seq opt 9        noptr-declarator parameters-and-qualifiers 10       noptr-declarator [ constant-expression opt ] attribute-specifier-seq opt 11       ( ptr-declarator ) 12    parameters-and-qualifiers: 13       ( parameter-declaration-clause ) cv-qualifier-seqafter 

roughly speaking, after 1->2, 2=4, 4->6, 4->6 should have ptr-operator ptr-operator ptr-operator then, use 4->5, 5=7, 7->8 first declarator; use 4->5, 5=7, 7->9 second , third declarators.

from [dcl.fct], pretty explicitly:

functions shall not have return type of type array or function, although may have return type of type pointer or reference such things. there shall no arrays of functions, although there can arrays of pointers functions.

with c++11, want:

std::function<int()> f(); std::function<int(double)> f(char); 

there confusion regarding c++ grammar. statement int f(char)(double); can parsed according grammar. here parse tree:

grammar

furthermore such parse meaningful based on [dcl.fct]/1:

in declaration t d d has form
    d1 ( parameter-declaration-clause ) cv-qualifier-seqopt
        ref-qualifieropt exception-specificationopt attribute-specifier-seqopt
, type of contained declarator-id in declaration t d1derived-declarator-type-list t”, type of declarator-id in dderived-declarator-type-list function of (parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt returning t”.

in example t == int, d == f(char)(double), d1 == f(char). type of declarator-id in t d1 (int f(char)) "function of (char) returning int". derived-declarator-type-list "function of (char) returning". thus, type of f read "function of (char) returning function of (double) returning int."

it's ado nothing, explicitly disallowed declarator form. not grammar.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -