This is a follow up on this question: previous question.
I will repeat the code from the previous question just to make this question self-contained. The code below compiles and does not issue any warnings if compiled using gcc 4.8.3. with -std=c++1y. However, it does issue warnings if compiled with -std=c++0x flag. However, in the previous question it was pointed out (see comments) that the code does not compile using gcc 4.9.0. Coming from high level scientific/data analysis/symbolic/interpreted languages background, I must admit that, at present, I do not fully understand the mechanics behind the implementation of the auto 'type'. Thus, I would appreciate if anyone could answer the following questions:
1). Will the code below become valid C++ with the (full) introduction of the C++14 standard?
2). If yes, would this code be considered a good style? If not, why not?
3). Why does the code below seem to compile and work (sometimes) using C++11 compilers? Alternatively, why does it not always work? Are there any specific flags/options/settings/os settings that could prevent it from working?
template<int N> auto getOutputPort2();
template<> auto getOutputPort2<0>();
template<> auto getOutputPort2<1>();
template<>
auto getOutputPort2<0>()
{
return std::unique_ptr<int>(new int(10));
}
template<>
auto getOutputPort2<1>()
{
return std::unique_ptr<string>(new string("asdf"));
}
Aucun commentaire:
Enregistrer un commentaire