NextOne
NextOne

Reputation: 35

why tuple couldn’t deduce std::tuple<void> template parameter C2641, tuple supports CTAD

import <tuple>;
import <iostream>;
import <string>;

using namespace std;

template<typename TupleType, int n>
class TuplePrintHelper
{
public:
    TuplePrintHelper(const TupleType& t)
    {
        TuplePrintHelper<TupleType, n - 1> tp{ t };
        cout << get<n - 1>(t) << endl;
    }
};

template<typename TupleType>
class TuplePrintHelper<TupleType, 0>
{
public:
    TuplePrintHelper(const TupleType&){}
};

template<typename T>
void tuplePrint(const T& t)
{
    TuplePrintHelper<T, tuple_size<T>::value> tph{ t };
};

int main()
{
    tuple t1{167, "Testaa"s,false, 2.3 }; //this lines show all err
    tuplePrint(t1);
}

visual studio2022 run show

C2641 tuple couldn’t deduce std::tuple template parameter , this shows tuple supports CTAD so what is the problem how to solve this problem

C2780 “std::tuple<_Types...> std::tuple(void)”: should input 0 ‌parameter,but Provided 4 parameters

C2780 “std::tuple<_Types...> std::tuple(std::tuple<_Types...>)”: should input 1 ‌parameter,but Provided 4

i learn from

https://github.com/carlesmartin85/procpp5e/blob/65aedda6a92745beca48a5041411465a33cdf4cd/code/c26_code/16_PrintTuple/02_PrintTupleSimplified.cpp

how to solve this problem, i want to CTAD not tuple<int, string_view, bool, double> i try to update but still not work version

Upvotes: 0

Views: 90

Answers (1)

Minxin Yu - MSFT
Minxin Yu - MSFT

Reputation: 4304

Version 17.12.0 Preview 1.0.

New Console project:

To use import,

  1. Set C++ latest.
  2. Set properties -> C++ -> scan source for Module Dependencies -> true

enter image description here

enter image description here

Upvotes: 0

Related Questions