summaryrefslogtreecommitdiff
path: root/boost/gil/extension/dynamic_image/variant.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/gil/extension/dynamic_image/variant.hpp')
-rw-r--r--boost/gil/extension/dynamic_image/variant.hpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/boost/gil/extension/dynamic_image/variant.hpp b/boost/gil/extension/dynamic_image/variant.hpp
index 24460ca6bf..1ab53b549d 100644
--- a/boost/gil/extension/dynamic_image/variant.hpp
+++ b/boost/gil/extension/dynamic_image/variant.hpp
@@ -29,7 +29,8 @@
#include <algorithm>
#include <typeinfo>
#include <boost/bind.hpp>
-
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/bool.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/sizeof.hpp>
@@ -48,6 +49,7 @@ namespace detail {
};
template <typename T, typename Bits> void copy_construct_in_place(const T& t, Bits& bits);
template <typename Bits> struct copy_construct_in_place_fn;
+ template <typename Types> struct type_to_index_fn;
}
/**
\brief Represents a concrete instance of a run-time specified type from a set of types
@@ -100,6 +102,11 @@ public:
// Throws std::bad_cast if T is not in Types
template <typename T> explicit variant(const T& obj){ _index=type_id<T>(); if (_index==NUM_TYPES) throw std::bad_cast(); detail::copy_construct_in_place(obj, _bits); }
+ template <typename Types2> explicit variant(const variant<Types2>& obj) : _index(apply_operation(obj,detail::type_to_index_fn<Types>())) {
+ if (_index==NUM_TYPES) throw std::bad_cast();
+ apply_operation(obj, detail::copy_construct_in_place_fn<base_t>(_bits));
+ }
+
// When doSwap is true, swaps obj with the contents of the variant. obj will contain default-constructed instance after the call
template <typename T> explicit variant(T& obj, bool do_swap);
@@ -161,6 +168,13 @@ namespace detail {
return x==*gil_reinterpret_cast_c<const T*>(&_dst);
}
};
+
+ template <typename Types>
+ struct type_to_index_fn {
+ typedef std::size_t result_type;
+
+ template <typename T> result_type operator()(const T&) const { return detail::type_to_index<Types,T>::value; }
+ };
}
// When doSwap is true, swaps obj with the contents of the variant. obj will contain default-constructed instance after the call