Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to compare data type of a tuple parameter?

How i could compare the data type of each tuple argument?

enum WinGetCmds {
    WINGET_TITLE, WINGET_CLASS
};


template <typename... Args>
auto WinGet(WinGetCmds cmd, Args&&... args)
{
    auto pack = std::make_tuple(std::forward<Args>(args)...);

    switch (cmd)
    {
    case WINGET_TITLE:
    {
        auto arg_1 = std::get<0>(pack);

        if constexpr (std::is_same<arg_1, std::wstring>::value)
        {
          //...
        }
        else if constexpr (std::is_same<arg_1, HWND>::value)
        {
          //...
        }    

    }
    break;

    }
}


WinGet(WINGET_TITLE, L"ABC");

In the template above I’m getting an error in the constexpr line:

'std::is_same': 'arg_1' is not a valid template type argument for parameter '_Ty1'7

What other way I could compare the data type of arg_1?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What other way I could compare the data type of arg_1?

The problem is that arg_1 is an expression when you use it in an expression. That is, you cannot use it as a template type parameter for is_same which is what the error is trying to say.

To solve this, you could use, decltype(arg_1).

Working demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading