 |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Go to the documentation of this file.
12 #include <initializer_list>
15 #include <type_traits>
20 #define TR2_OPTIONAL_REQUIRES(...) \
21 typename std::enable_if<__VA_ARGS__::value, bool>::type = false
30 template <std::
size_t I>
54 return static_cast<T&&
>(t);
60 static_assert(!std::is_lvalue_reference<T>::value,
"!!");
61 return static_cast<T&&
>(t);
71 #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
73 #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) \
74 ((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR)))
77 #if defined(__CUDA_ARCH__)
78 #define TR2_OPTIONAL_HOST_CONSTEXPR
80 #define TR2_OPTIONAL_HOST_CONSTEXPR constexpr
86 #if (defined _MSC_VER)
89 return std::addressof(ref);
100 template <class X, size_t S = sizeof(std::declval<X&>().operator&())>
105 constexpr
static bool value = has_overload<T>(
true);
108 template <
typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
113 template <
typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)>
115 return std::addressof(ref);
142 : logic_error{what_arg} {}
144 : logic_error{what_arg} {}
154 template <
class...
Args>
168 template <
class...
Args>
188 template <
class...
Args>
195 std::is_constructible<T, std::initializer_list<U>>)>
197 std::initializer_list<U> il,
220 template <
class...
Args>
227 std::is_constructible<T, std::initializer_list<U>>)>
229 std::initializer_list<U> il,
238 std::is_trivially_destructible<T>::value,
239 constexpr_optional_base<
typename std::remove_const<
247 std::is_trivially_destructible<U>::value,
258 constexpr
bool initialized()
const noexcept {
264 constexpr
const T* dataptr()
const {
268 constexpr
const T& contained_val()
const& {
271 constexpr T&& contained_val() && {
276 void clear() noexcept {
277 if (initialized()) dataptr()->~T();
281 template <
class...
Args>
282 void initialize(
Args&&... args) noexcept(
283 noexcept(T(std::forward<Args>(args)...))) {
285 ::new (
static_cast<void*
>(dataptr())) T(std::forward<Args>(args)...);
289 template <
class U,
class...
Args>
290 void initialize(std::initializer_list<U> il,
Args&&... args) noexcept(
291 noexcept(T(il, std::forward<Args>(args)...))) {
293 ::new (
static_cast<void*
>(dataptr()))
294 T(il, std::forward<Args>(args)...);
302 constexpr
optional() noexcept : OptionalBase<T>() {};
306 if (rhs.initialized()) {
307 ::new (
static_cast<void*
>(dataptr())) T(*rhs);
308 OptionalBase<T>::init_ =
true;
313 std::is_nothrow_move_constructible<T>::value)
314 : OptionalBase<T>() {
315 if (rhs.initialized()) {
316 ::new (
static_cast<void*
>(dataptr())) T(std::move(*rhs));
317 OptionalBase<T>::init_ =
true;
327 template <
typename U = T,
333 std::is_convertible<U&&, T>)>
334 constexpr
optional(U&& u) : OptionalBase<T>(
std::forward<U>(u)) {}
337 template <
typename U = T,
343 !std::is_convertible<U&&, T>)>
344 explicit constexpr
optional(U&& u) : OptionalBase<T>(
std::forward<U>(u)) {}
346 template <
class...
Args>
348 : OptionalBase<T>(
in_place_t{}, constexpr_forward<Args>(args)...) {}
353 std::is_constructible<T, std::initializer_list<U>>)>
355 std::initializer_list<U> il,
357 : OptionalBase<T>(
in_place_t{}, il, constexpr_forward<Args>(args)...) {}
369 if (initialized() ==
true && rhs.initialized() ==
false)
371 else if (initialized() ==
false && rhs.initialized() ==
true)
373 else if (initialized() ==
true && rhs.initialized() ==
true)
374 contained_val() = *rhs;
379 std::is_nothrow_move_assignable<T>::value &&
380 std::is_nothrow_move_constructible<T>::value) {
381 if (initialized() ==
true && rhs.initialized() ==
false)
383 else if (initialized() ==
false && rhs.initialized() ==
true)
384 initialize(std::move(*rhs));
385 else if (initialized() ==
true && rhs.initialized() ==
true)
386 contained_val() = std::move(*rhs);
390 template <
class U = T>
392 typename std::enable_if<
393 std::is_constructible<T, U>::value &&
396 (std::is_scalar<T>::value ||
399 std::is_assignable<T&, U>::value,
402 contained_val() = std::forward<U>(v);
404 initialize(std::forward<U>(v));
409 template <
class...
Args>
412 initialize(std::forward<Args>(args)...);
415 template <
class U,
class...
Args>
418 initialize<U,
Args...>(il, std::forward<Args>(args)...);
423 std::is_nothrow_move_constructible<T>::value &&
424 noexcept(
std::swap(std::declval<T&>(), std::declval<T&>()))) {
425 if (initialized() ==
true && rhs.initialized() ==
false) {
426 rhs.initialize(std::move(**
this));
428 }
else if (initialized() ==
false && rhs.initialized() ==
true) {
429 initialize(std::move(*rhs));
431 }
else if (initialized() ==
true && rhs.initialized() ==
true) {
439 explicit constexpr
operator bool() const noexcept {
return initialized(); }
440 constexpr
bool has_value() const noexcept {
return initialized(); }
447 assert(initialized());
456 assert(initialized());
457 return contained_val();
461 assert(initialized());
481 return std::move(contained_val());
486 return *
this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
493 : detail_::convert<T>(constexpr_forward<V>(v));
512 static_assert(
sizeof(T) == 0,
513 "optional references is ill-formed, \
514 consider use optional of a std::reference_wrapper of type T to \
515 hold a reference if you really need to");
517 static_assert(!std::is_same<T, nullopt_t>::value,
"bad T");
518 static_assert(!std::is_same<T, in_place_t>::value,
"bad T");
527 template <
typename U = T>
530 template <
typename U = T>
558 template <
typename U>
567 template <
typename U>
568 auto operator=(U&& rhs) noexcept ->
575 void emplace(T&&) =
delete;
593 explicit constexpr
operator bool() const noexcept {
return ref !=
nullptr; }
595 constexpr
bool has_value() const noexcept {
return ref !=
nullptr; }
599 return *
this ? **this
601 constexpr_forward<V>(v));
605 void reset() noexcept { ref =
nullptr; }
610 static_assert(
sizeof(T) == 0,
"optional rvalue references disallowed");
616 return bool(
x) != bool(
y) ? false : bool(
x) ==
false ? true : *
x == *
y;
626 return (!
y) ? false : (!
x) ?
true : *
x < *
y;
708 return bool(
x) ? *
x == v :
false;
713 return bool(
x) ? v == *
x :
false;
718 return bool(
x) ? *
x != v :
true;
723 return bool(
x) ? v != *
x :
true;
728 return bool(
x) ? *
x < v :
true;
733 return bool(
x) ? v > *
x :
true;
738 return bool(
x) ? *
x > v :
false;
743 return bool(
x) ? v < *
x :
false;
748 return bool(
x) ? *
x >= v :
false;
753 return bool(
x) ? v <= *
x :
false;
758 return bool(
x) ? *
x <= v :
true;
763 return bool(
x) ? v >= *
x :
true;
769 return bool(
x) ? *
x == v :
false;
774 return bool(
x) ? v == *
x :
false;
779 return bool(
x) ? *
x != v :
true;
784 return bool(
x) ? v != *
x :
true;
789 return bool(
x) ? *
x < v :
true;
794 return bool(
x) ? v > *
x :
true;
799 return bool(
x) ? *
x > v :
false;
804 return bool(
x) ? v < *
x :
false;
809 return bool(
x) ? *
x >= v :
false;
814 return bool(
x) ? v <= *
x :
false;
819 return bool(
x) ? *
x <= v :
true;
824 return bool(
x) ? v >= *
x :
true;
830 return bool(
x) ? *
x == v :
false;
835 return bool(
x) ? v == *
x :
false;
840 return bool(
x) ? *
x != v :
true;
845 return bool(
x) ? v != *
x :
true;
850 return bool(
x) ? *
x < v :
true;
855 return bool(
x) ? v > *
x :
true;
860 return bool(
x) ? *
x > v :
false;
865 return bool(
x) ? v < *
x :
false;
870 return bool(
x) ? *
x >= v :
false;
875 return bool(
x) ? v <= *
x :
false;
880 return bool(
x) ? *
x <= v :
true;
885 return bool(
x) ? v >= *
x :
true;
908 template <
typename T>
918 template <
typename T>
929 #undef TR2_OPTIONAL_REQUIRES
930 #undef TR2_OPTIONAL_ASSERTED_EXPRESSION
931 #undef TR2_OPTIONAL_HOST_CONSTEXPR
constexpr T const & value() const &
Definition: Optional.h:465
Definition: Optional.h:133
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
Definition: Optional.h:128
constexpr T & value() &
Definition: Optional.h:472
~storage_t()
Definition: Optional.h:158
constexpr optional_base(const T &v)
Definition: Optional.h:183
constexpr bool operator<(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:625
constexpr std::remove_reference< T >::type && constexpr_move(T &&t) noexcept
Definition: Optional.h:65
normal_z x
Definition: my_point_types.h:165
constexpr bool has_value() const noexcept
Definition: Optional.h:440
bad_optional_access(const char *what_arg)
Definition: Optional.h:143
constexpr optional(const optional &rhs) noexcept
Definition: Optional.h:533
constexpr optional< typename std::decay< T >::type > make_optional(T &&v)
Definition: Optional.h:895
Definition: Optional.h:26
#define TR2_OPTIONAL_HOST_CONSTEXPR
Definition: Optional.h:80
storage_t< T > storage_
Definition: Optional.h:178
constexpr bool has_value() const noexcept
Definition: Optional.h:595
constexpr T & operator*() &
Definition: Optional.h:455
auto operator=(U &&v) -> typename std::enable_if< std::is_constructible< T, U >::value &&!std::is_same< typename std::decay< U >::type, optional< T >>::value &&(std::is_scalar< T >::value||std::is_same< typename std::decay< U >::type, T >::value) &&std::is_assignable< T &, U >::value, optional & >::type
Definition: Optional.h:391
constexpr T && value() &&
Definition: Optional.h:479
optional_base(in_place_t, std::initializer_list< U > il, Args &&... args)
Definition: Optional.h:196
constexpr constexpr_optional_base(in_place_t, std::initializer_list< U > il, Args &&... args)
Definition: Optional.h:228
cloudViewer::utility::optional< T & > argument_type
Definition: Optional.h:921
constexpr constexpr_optional_base(const T &v)
Definition: Optional.h:214
in_place_type_t()=default
in_place_index_t()=default
constexpr bool operator==(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:615
constexpr optional(U &&u)
Definition: Optional.h:334
constexpr optional(in_place_t, T &v) noexcept
Definition: Optional.h:535
Definition: Optional.h:31
constexpr T value_or(V &&v) const &
Definition: Optional.h:485
constexpr optional_base() noexcept
Definition: Optional.h:180
constexpr optional(nullopt_t) noexcept
Definition: Optional.h:303
void swap(optional< T > &rhs) noexcept(std::is_nothrow_move_constructible< T >::value &&noexcept(std::swap(std::declval< T & >(), std::declval< T & >())))
Definition: Optional.h:422
Definition: Optional.h:94
Definition: Optional.h:162
T value_
Definition: Optional.h:164
constexpr constexpr_optional_base(in_place_t, Args &&... args)
Definition: Optional.h:221
void reset() noexcept
Definition: Optional.h:605
void reset() noexcept
Definition: Optional.h:497
constexpr T const * operator->() const
Definition: Optional.h:442
constexpr T * static_addressof(T &ref)
Definition: Optional.h:109
void swap(optional< T > &x, optional< T > &y) noexcept(noexcept(x.swap(y)))
Definition: Optional.h:890
constexpr constexpr_storage_t(trivial_init_t) noexcept
Definition: Optional.h:166
constexpr static bool has_overload(bool)
Definition: Optional.h:101
Definition: Optional.h:207
constexpr optional() noexcept
Definition: Optional.h:302
constexpr static bool value
Definition: Optional.h:105
constexpr struct cloudViewer::utility::trivial_init_t trivial_init
constexpr std::decay< T >::type value_or(V &&v) const
Definition: Optional.h:598
hash< T >::result_type result_type
Definition: Optional.h:920
normal_z y
Definition: my_point_types.h:168
constexpr storage_t(trivial_init_t) noexcept
Definition: Optional.h:152
void swap(optional< T & > &rhs) noexcept
Definition: Optional.h:577
void emplace(T &v) noexcept
Definition: Optional.h:573
constexpr T * operator->()
Definition: Optional.h:446
bool init_
Definition: Optional.h:177
constexpr result_type operator()(argument_type const &arg) const
Definition: Optional.h:913
constexpr T && operator*() &&
Definition: Optional.h:460
hash< T >::result_type result_type
Definition: Optional.h:910
bad_optional_access(const std::string &what_arg)
Definition: Optional.h:141
~constexpr_storage_t()=default
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370
void emplace(std::initializer_list< U > il, Args &&... args)
Definition: Optional.h:416
constexpr optional(in_place_t, Args &&... args)
Definition: Optional.h:347
constexpr constexpr_optional_base() noexcept
Definition: Optional.h:211
optional(optional &&rhs) noexcept(std::is_nothrow_move_constructible< T >::value)
Definition: Optional.h:312
bool init_
Definition: Optional.h:208
unsigned char dummy_
Definition: Optional.h:163
~optional_base()
Definition: Optional.h:201
constexpr T const & operator*() const &
Definition: Optional.h:451
constexpr T * operator->() const
Definition: Optional.h:580
Definition: Optional.h:139
constexpr bool operator>(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:630
constexpr static bool has_overload(...)
Definition: Optional.h:96
Definition: Optional.h:132
optional & operator=(nullopt_t) noexcept
Definition: Optional.h:363
constexpr optional(nullopt_t) noexcept
Definition: Optional.h:525
cloudViewer::utility::optional< T > argument_type
Definition: Optional.h:911
constexpr T value_or(V &&v) &&
Definition: Optional.h:490
#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR)
Definition: Optional.h:73
Definition: Optional.h:44
optional(const optional &rhs)
Definition: Optional.h:305
optional & operator=(const optional &rhs)
Definition: Optional.h:368
unsigned char dummy_
Definition: Optional.h:149
constexpr in_place_t in_place
Definition: Optional.h:40
constexpr bool operator!=(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:620
constexpr constexpr_optional_base(T &&v)
Definition: Optional.h:217
T value_type
Definition: Optional.h:299
constexpr T && constexpr_forward(typename std::remove_reference< T >::type &t) noexcept
Definition: Optional.h:52
constexpr result_type operator()(argument_type const &arg) const
Definition: Optional.h:923
constexpr_storage_t< T > storage_
Definition: Optional.h:209
constexpr optional(U &u) noexcept
Definition: Optional.h:528
constexpr nullopt_t nullopt
Definition: Optional.h:136
Definition: Optional.h:148
constexpr optional() noexcept
Definition: Optional.h:523
constexpr constexpr_storage_t(Args &&... args)
Definition: Optional.h:169
optional_base(in_place_t, Args &&... args)
Definition: Optional.h:189
optional & operator=(nullopt_t) noexcept
Definition: Optional.h:543
#define TR2_OPTIONAL_REQUIRES(...)
Definition: Optional.h:20
void emplace(Args &&... args)
Definition: Optional.h:410
constexpr U convert(U v)
Definition: Optional.h:122
typename std::conditional< std::is_trivially_destructible< T >::value, constexpr_optional_base< typename std::remove_const< T >::type >, optional_base< typename std::remove_const< T >::type > >::type OptionalBase
Definition: Optional.h:241
Definition: Optional.h:509
constexpr nullopt_t(init)
Definition: Optional.h:134
constexpr bool operator>=(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:640
auto operator=(U &&rhs) noexcept -> typename std::enable_if< std::is_same< typename std::decay< U >::type, optional< T & >>::value, optional & >::type
Definition: Optional.h:559
constexpr optional_base(T &&v)
Definition: Optional.h:185
~constexpr_optional_base()=default
char type
Definition: FileIOFactory.cpp:131
constexpr optional(in_place_t, std::initializer_list< U > il, Args &&... args)
Definition: Optional.h:354
Definition: Optional.h:36
constexpr T & value() const
Definition: Optional.h:588
optional & operator=(optional &&rhs) noexcept(std::is_nothrow_move_assignable< T >::value &&std::is_nothrow_move_constructible< T >::value)
Definition: Optional.h:378
constexpr storage_t(Args &&... args)
Definition: Optional.h:155
Definition: Optional.h:176
constexpr T & operator*() const
Definition: Optional.h:584
constexpr bool operator<=(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:635
T value_
Definition: Optional.h:150