C ++ concepts are the same and assignable

I recently experimented with C ++ concepts. I am trying to use the definitions from the following Extensions documents:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4569.pdf

Definitions and customs Sameconfuse me. For reasons unknown to me, the authors did not give an explicit definition. Therefore, I use:

template <class T, class U>
concept bool Same()
{
  return std::is_same<T, U>::value;
}

The problem is that the document gives the following definition for Assignable:

template <class T, class U>
concept bool Assignable()
{
  return Common<T, U>() && requires(T&& a, U&& b) {
    { std::forward<T>(a) = std::forward<U>(b) } -> Same<T&>;
  };
}

This does not work (under GCC 6.3): a simple check Assignable<int&, int&&>()gives me false(I confirmed that the part Commonis ok). I need to change Same<T&>to T&so that it looks like it works. The same tags are Same<Type>also used in some other places.

My questions:

  • Is my definition correct Same?
  • Same<T&> T&? ?

.

+2
2

, , .

Same, ( ), .

-> Type , Type. -> Same<Type> , Type. .

. , , , N4569. GitHub:

https://github.com/ericniebler/stl2/issues/330

, N4569, , ,

template <typename U>
f(U)
requires Same<T&, U>()

- , , l T, U T T&. Same<T&>&& Assignable. :

template <typename U>
f(U&&)
requires Same<T&, U>()

- l T, U T&.

- , , , . GitHub:

https://github.com/CaseyCarter/cmcstl2

, ++, .

+3

Same : Ranges TS , Same<T, U>() Same<U, T>(), "T - U":

template <class T, class U>
requires Same<T, U>()
void foo(); // #1

template <class T, class U>
requires Same<U, T>()
void foo(); // redeclaration of #1

template <class T>
requires Same<int, T>()
void bar(); // #2

template <class T>
requires Same<T, int>()
void bar(); // redeclaration of #2

, :

is_same_v<T, U>
is_same_v<U, T>
is_same_v<T, int>
is_same_v<int, T>

. Same .

+3

Source: https://habr.com/ru/post/1673538/


All Articles