Last active
January 31, 2021 02:04
-
-
Save airglow923/e496d641b0917f02516a0944dc2a8e1c to your computer and use it in GitHub Desktop.
Move only C++ code example introduced by Ivan Čukić
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <type_traits> // is_nothrow_constructible, is_nothrow_assignable | |
| // is_nothrow_convertible, is_constructible | |
| // is_assignable, is_convertible | |
| #include <memory> // make_unique | |
| #include <string> // operator""s | |
| using namespace std::string_literals; | |
| namespace detail { | |
| template <typename T, typename U> | |
| inline constexpr bool linear_usable_as_v = | |
| std::is_nothrow_constructible_v<T, U> && | |
| std::is_nothrow_assignable_v<T&, U> && | |
| std::is_nothrow_convertible_v<U, T>; | |
| template <typename T, typename U> | |
| inline constexpr bool linear_unusable_as_v = | |
| !std::is_constructible_v<T, U> && | |
| !std::is_assignable_v<T&, U> && | |
| !std::is_convertible_v<U, T>; | |
| } // detail | |
| template <typename T> | |
| concept Linear = | |
| std::is_nothrow_destructible_v<T> && | |
| detail::linear_usable_as_v<T, T> && | |
| detail::linear_usable_as_v<T, T&&> && | |
| detail::linear_unusable_as_v<T, T&> && | |
| detail::linear_unusable_as_v<T, const T&> && | |
| detail::linear_unusable_as_v<T, const T>; | |
| auto main() -> int { | |
| Linear auto ptr = std::make_unique<int>(); | |
| // Linear auto str = "This is literal std::string"s; // error | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The full talk can be found here.