C++ 自动推断法';s返回类型

C++ 自动推断法';s返回类型,c++,c++11,type-inference,C++,C++11,Type Inference,我有以下职能: //method takes 2 or more template parameters template <class A1, class A2, class ...Ax> Value<FooMany> getValue() { //note, FooAll's ctor takes std::string and std::initializer_list<std::size_t> FooAll<Item&

我有以下职能:

//method takes 2 or more template parameters    
template <class A1, class A2, class ...Ax>
Value<FooMany> getValue() {

    //note, FooAll's ctor takes std::string and std::initializer_list<std::size_t>

    FooAll<Item> hairyStructure("abc", { Foo<A1>::getIndex(), Foo<A2>::getIndex(), Foo<Ax>::getIndex() ... } );
    return Value<FooMany>(someData, hairyStructure);
}

//method takes only 1 template parameter
template <class A>
Value<FooSingle> getValue() {

    //note, FooOne's ctor takes std::string and std::size_t

    FooOne<Item> hairyStructure("abc", Foo<A>::getIndex() );
    return Value<FooSingle>(someData, hairyStructure);
}
//方法接受2个或多个模板参数
模板
值getValue(){
//注意,FooAll的ctor接受std::string和std::initializer\u列表
FooAll hairyStructure(“abc”),{Foo

谢谢。

#包括
#include <type_traits>

template <class A1, class... Ax>
auto getValue()
    -> Value<typename std::conditional<sizeof...(Ax) == 0
                                     , FooSingle, FooMany>::type>
{
    typename std::conditional<sizeof...(Ax) == 0
                            , FooOne<Item> 
                            , FooAll<Item>>::type
              hairyStructure("abc", { Foo<A1>::getIndex(), Foo<Ax>::getIndex()... } );
    return Value<typename std::conditional<sizeof...(Ax) == 0
                                         , FooSingle, FooMany>::type>(hairyStructure);
}
模板 自动获取值() ->价值观 { typename std::conditional::type
hairyStructure(“abc”,{Foo

类型是一回事,但是您如何在函数中编写
return
-语句?我不明白为什么会有显式的'FooAll'。它应该在FooAll和FooOne之间变化,对吗?我真的觉得这比使用两个重载更可读。