try working around an error with MSVC2017

`error C2338: Sorry: std::any doesn't support over-aligned types at this time.`
This commit is contained in:
Sébastien Loriot 2023-08-14 14:02:39 +02:00
parent 2549f47191
commit 5db243629a
1 changed files with 9 additions and 9 deletions

View File

@ -29,20 +29,20 @@
#include <variant> #include <variant>
#include <optional> #include <optional>
#include <any> #include <boost/any.hpp>
#include <memory> #include <memory>
namespace CGAL { namespace CGAL {
class Object class Object
{ {
std::shared_ptr<std::any> obj; std::shared_ptr<boost::any> obj;
// returns an any pointer from a variant // returns an any pointer from a variant
struct Any_from_variant { struct Any_from_variant {
template<typename T> template<typename T>
std::any* operator()(const T& t) const { boost::any* operator()(const T& t) const {
return new std::any(t); return new boost::any(t);
} }
}; };
@ -59,7 +59,7 @@ class Object
Object() : obj() { } Object() : obj() { }
template <class T> template <class T>
Object(T && t, private_tag) : obj(new std::any(std::forward<T>(t))) { } Object(T && t, private_tag) : obj(new boost::any(std::forward<T>(t))) { }
// implicit constructor from optionals containing variants // implicit constructor from optionals containing variants
template<typename ... T> template<typename ... T>
@ -74,7 +74,7 @@ class Object
template <class T> template <class T>
bool assign(T &t) const bool assign(T &t) const
{ {
const T* res = std::any_cast<T>(obj.get()); const T* res = boost::any_cast<T>(obj.get());
if (!res) return false; if (!res) return false;
t = *res; t = *res;
return true; return true;
@ -103,7 +103,7 @@ class Object
template <class T> template <class T>
bool is() const bool is() const
{ {
return obj && std::any_cast<T>(obj.get()); return obj && boost::any_cast<T>(obj.get());
} }
const std::type_info & type() const const std::type_info & type() const
@ -157,14 +157,14 @@ template <class T>
inline inline
const T * object_cast(const Object * o) const T * object_cast(const Object * o)
{ {
return std::any_cast<T>((o->obj).get()); return boost::any_cast<T>((o->obj).get());
} }
template <class T> template <class T>
inline inline
T object_cast(const Object & o) T object_cast(const Object & o)
{ {
const T * result = std::any_cast<T>((o.obj).get()); const T * result = boost::any_cast<T>((o.obj).get());
if (!result) if (!result)
throw Bad_object_cast(); throw Bad_object_cast();
return *result; return *result;