Skip to content

Commit

Permalink
Pair_optional_adaptor no longer inherits from std::optional
Browse files Browse the repository at this point in the history
first is now non-reference
removed union to avoid default construction (-> T is supposed to be lightweight)
  • Loading branch information
soesau committed Feb 19, 2024
1 parent 17ab4fd commit 23cc636
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
42 changes: 20 additions & 22 deletions STL_Extension/include/CGAL/Pair_optional_adaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ namespace CGAL {

// T is supposed to be a handle
template<typename T>
class Pair_optional_adaptor : public std::optional<T> {
class Pair_optional_adaptor {
public:
Pair_optional_adaptor(const std::optional<T>& obj) : std::optional<T>(obj), second(obj.has_value()), first(t_storage.t) {
Pair_optional_adaptor(const std::optional<T>& obj) : first(), second(obj.has_value()) {
if (obj.has_value())
t_storage.t = *obj;
} //boost::tuples::detail::swallow_assign
first = *obj;
}

Pair_optional_adaptor(const std::nullopt_t& obj) : first(), second(false) {}

Pair_optional_adaptor(const std::nullopt_t& obj) : std::optional<T>(std::nullopt), second(false), first(t_storage.t) {}
Pair_optional_adaptor(std::pair<T, bool>& p) : first(p.first), second(p.second) {}

Pair_optional_adaptor(std::pair<T, bool>& p) : std::optional<T>(p.second ? p.first : std::optional<T>()), first(t_storage.t), second(p.second), t_storage(p.first) {}
operator std::optional<T>() {
if (second)
return std::optional<T>(first);
else
return std::nullopt;
}

#ifndef CGAL_NO_DEPRECATED_CODE
CGAL_DEPRECATED_MSG("you are using the deprecated API, please update your code")
Expand Down Expand Up @@ -60,31 +67,22 @@ class Pair_optional_adaptor : public std::optional<T> {
}

CGAL_DEPRECATED_MSG("you are using the deprecated API, please update your code")
operator std::tuple<T&, std::_Ignore const&>() {
return std::tuple<T&, std::_Ignore const&>(first, std::ignore);
operator std::tuple<T&, decltype(std::ignore)&>() {
return std::tuple<T&, decltype(std::ignore)&>(first, std::ignore);
}

CGAL_DEPRECATED_MSG("you are using the deprecated API, please update your code")
operator std::tuple<std::_Ignore const&, bool&>() {
return std::tuple<std::_Ignore const&, bool&>(std::ignore, second);
operator std::tuple<decltype(std::ignore)&, bool&>() {
return std::tuple<decltype(std::ignore)&, bool&>(std::ignore, second);
}

CGAL_DEPRECATED_MSG("you are using the deprecated API, please update your code")
operator std::tuple<std::_Ignore const&, std::_Ignore const&>() {
return std::tuple<std::_Ignore const&, std::_Ignore const&>(std::ignore, std::ignore);
operator std::tuple<decltype(std::ignore)&, decltype(std::ignore)&>() {
return std::tuple<decltype(std::ignore)&, decltype(std::ignore)&>(std::ignore, std::ignore);
}
#endif

T &first;
T first;
bool second;

private:
union T_value {
T t;
int i;
T_value() : i(0) {}
T_value(T t) : t(t) {}
} t_storage;
};

} // CGAL
Expand Down
1 change: 1 addition & 0 deletions Surface_mesh/include/CGAL/Surface_mesh/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <string>
#include <typeinfo>
#include <vector>
#include <optional>

namespace CGAL {

Expand Down

0 comments on commit 23cc636

Please sign in to comment.