Why is a struct with const members assignable?
-
12-11-2019 - |
Вопрос
I needed to use the std::is_assignable
type traits, which happens not to be available in the oldest compiler version that I want to support. Since I had to implement this myself (okay, I admit it, there was some interwebs peeking), I now wonder if this is a bug in my implementation or a general problem of std::is_assignable
.
First of all, this is my test struct:
struct Bar {
bool const cb; // this should kill the default assignment operator
int i;
};
and here is my stdreplace::is_assignable
template <typename T> struct is_assignable : private std::__sfinae_types {
private:
template <typename T1>
static decltype(std::declval<T1>() = std::declval<T1>(),__one()) test(int);
template <typename T1>
static __two test(...);
public:
static bool const value = sizeof(test<T>(0)) == sizeof(__one);
};
However, it tells me, Bar
is assignable:
int: 1
Bar: 1
int[2]: 0
Where is the problem?
Нет правильного решения
Не связан с StackOverflow