Skip to content
Permalink
Browse files

Example conversion for `optional`, using [[trivially_relocatable]].

  • Loading branch information...
Quuxplusone committed Nov 19, 2018
1 parent 999b73a commit ccae878fde6e6ff2e84b78d45754fff76e1c7764
Showing with 22 additions and 2 deletions.
  1. +8 −0 include/__config
  2. +14 −2 include/optional
@@ -1281,6 +1281,14 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
#define _LIBCPP_HAS_NO_IS_AGGREGATE
#endif

#ifndef _LIBCPP_TRIVIALLY_RELOCATABLE
#if __has_extension(trivially_relocatable)
#define _LIBCPP_TRIVIALLY_RELOCATABLE [[clang::trivially_relocatable]]
#else
#define _LIBCPP_TRIVIALLY_RELOCATABLE
#endif
#endif

#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
#define _LIBCPP_HAS_NO_COROUTINES
#endif
@@ -580,13 +580,25 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base<
(is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)
>;

template <class _Tp, bool = is_trivially_relocatable<_Tp>::value>
struct __optional_relocate_base : __optional_move_assign_base<_Tp>
{
using __optional_move_assign_base<_Tp>::__optional_move_assign_base;
};

template <class _Tp>
struct _LIBCPP_TRIVIALLY_RELOCATABLE __optional_relocate_base<_Tp, true> : __optional_move_assign_base<_Tp>
{
using __optional_move_assign_base<_Tp>::__optional_move_assign_base;
};

template <class _Tp>
class optional
: private __optional_move_assign_base<_Tp>
: private __optional_relocate_base<_Tp>
, private __optional_sfinae_ctor_base_t<_Tp>
, private __optional_sfinae_assign_base_t<_Tp>
{
using __base = __optional_move_assign_base<_Tp>;
using __base = __optional_relocate_base<_Tp>;
public:
using value_type = _Tp;

0 comments on commit ccae878

Please sign in to comment.
You can’t perform that action at this time.