Skip to content

Instantly share code, notes, and snippets.

@airglow923
Last active January 31, 2021 02:04
Show Gist options
  • Select an option

  • Save airglow923/e496d641b0917f02516a0944dc2a8e1c to your computer and use it in GitHub Desktop.

Select an option

Save airglow923/e496d641b0917f02516a0944dc2a8e1c to your computer and use it in GitHub Desktop.
Move only C++ code example introduced by Ivan Čukić
#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
}
@airglow923
Copy link
Author

airglow923 commented Jan 30, 2021

The full talk can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment