incomplete return type in template function declaration; will c++0x'auto' work?

Discussion in 'C++' started by m0shbear, Mar 19, 2011.

  1. m0shbear

    m0shbear Guest

    Suppose I have the following classes: S T U, each of which is
    incompatible with the others.
    I want to have functions (ideally written) like this:
    template<> T foo<0>(const S&);
    template<> U foo<1>(const S&);

    Will the template declaration
    template<int IType> auto foo(const S&);
    work?
    Likewise for
    template<int IType, class Ret> Ret foo(const S&);

    The problem I see with the second one is that the expression
    void bar() {
    S s;
    U u = foo<1>(s); // *
    }
    will be ill-formed.
    Is such a notation for template foo<int>(const S&) even possible?
    m0shbear, Mar 19, 2011
    #1
    1. Advertising

  2. m0shbear

    m0shbear Guest

    Re: incomplete return type in template function declaration; willc++0x 'auto' work?

    A clarification:
    Can there exist a type lookup table to handle the mapping between the
    template arg type and the return type?
    As in:
    lookup-table {
    [ IType = 0 ] -> T
    [ IType = 1 ] -> U
    }

    Basically, indirect template-dependent return types wherein the
    mapping is only defined at specialization, and outside the template,
    the return type is deduced from the specialization of said template.
    m0shbear, Mar 19, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gk245
    Replies:
    2
    Views:
    1,189
    Christopher Benson-Manica
    May 6, 2006
  2. verec
    Replies:
    2
    Views:
    1,016
    verec
    Jun 25, 2005
  3. Replies:
    4
    Views:
    585
  4. linkswanted
    Replies:
    1
    Views:
    885
  5. Luca Forlizzi
    Replies:
    4
    Views:
    447
    Luca Forlizzi
    Nov 14, 2010
Loading...

Share This Page