Weird compile-time error for variable template specialization

  • Thread starter Thread starter Valos1
  • Start date Start date
V

Valos1

Guest
I am on visual studio version 15.7.4 (2017). Error is "template or generic redefined". Code is:

#include"stdafx.h"
#include<iostream>

namespace traits {
template<typename T, typename U>
constexpr bool is_same = false;

template<typename T>
constexpr bool is_same<T, T> = true;
}

int main()
{
constexpr bool some{ traits::is_same<int const, int const> };
std::cout << some;
}


Interestingly enough, if i comment #include<iostream> and line with std::cout<<some or rename is_same to something else, then it will compile. Why is this happening? Thanks.



Edit: another one, not error, just intellisense red underline stuff this time:

template<typename T>
constexpr bool is_void{ false };

template<>
constexpr bool is_void<void>{ true };

template<>
constexpr bool is_void<void const>{ true };

the last 2 is_void are underlined in red and it says when hovering over the second one: "explicit specialization of variable "value_traits::is_void[with T=const void]" must precede its first use ()"

Continue reading...
 
Back
Top