0

I am doing some experiments here with metaprogramming and initially the idea was to find out if we can make sorted integer sequence unique at compile time. (This is unrelated to the question though)

I have enabled c++17 in my properties (I use VS2019) and this program gives me strange output when I want to find out the C++ standard.

#include <iostream>
#include <boost/mp11.hpp>
#include <type_traits>

namespace
{
    template <int... N>
    using seq = boost::mp11::mp_list_c<int, N...>;

    template <int... N>
    struct uniq
    {
        using type = boost::mp11::mp_unique<seq<N...>>;
    };
}

int main()
{
    static_assert(std::is_same_v<uniq<1, 2, 2, 2, 3, 3, 3>::type, seq<1, 2, 3>>,"Assertion Failed");
    static_assert(std::is_same_v<uniq<4, 1, 9, 9, 2, 2, 3, 1, 5>::type, seq<4, 1, 9, 2, 3, 5>>,"Assertion Failed");

    if (__cplusplus == 201703L) std::cout << "C++17\n";
    else if (__cplusplus == 201402L) std::cout << "C++14\n";
    else if (__cplusplus == 201103L) std::cout << "C++11\n";
    else if (__cplusplus == 199711L) std::cout << "C++98\n";
    else std::cout << "pre-standard C++\n";
    return 0;
}

This prints "C++98" and I wonder how this can be the case? I have enabled the c++17 from properties and I am clearly using some more advanced language features than c++98 (like variadic templates).
Does this ring a bell to anyone what could I miss?

Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76

1 Answers1

3

In Visual Studio, you must enable /Zc:__cplusplus in order to get the appropriate values.

This has something to do with backwards compatibility.

ChrisMM
  • 8,448
  • 13
  • 29
  • 48