Skip to content

Instantly share code, notes, and snippets.

@tomlankhorst
Created April 14, 2021 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomlankhorst/e4201eb36c2e75b3f89a1fde5f24d518 to your computer and use it in GitHub Desktop.
Save tomlankhorst/e4201eb36c2e75b3f89a1fde5f24d518 to your computer and use it in GitHub Desktop.
Decay optional type
template<typename T>
struct decay_optional {
using type = T;
};
template<typename T>
struct decay_optional<std::optional<T>> {
using type = T;
};
template<typename T>
struct decay_optional<boost::optional<T>> {
using type = T;
};
template<typename T>
using decay_optional_t = typename decay_optional<T>::type;
static_assert(std::is_same_v<decay_optional_t<std::byte>, std::byte>);
static_assert(std::is_same_v<decay_optional_t<std::optional<std::byte>>, std::byte>);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment