Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion immer/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,34 @@
#include <immer/memory_policy.hpp>

#include <cstddef>
#include <type_traits>

namespace immer {

namespace detail {
namespace arrays {
// Forward declarations for SFINAE
template <typename T, typename MemoryPolicy>
struct with_capacity;
template <typename T, typename MemoryPolicy>
struct no_capacity;
} // namespace arrays

// Type trait to detect internal array implementation types
template <typename T>
struct is_array_impl : std::false_type {};

template <typename T, typename MP>
struct is_array_impl<arrays::with_capacity<T, MP>> : std::true_type {};

template <typename T, typename MP>
struct is_array_impl<arrays::no_capacity<T, MP>> : std::true_type {};

template <typename T>
inline constexpr bool is_array_impl_v = is_array_impl<std::decay_t<T>>::value;

} // namespace detail

namespace detail {

template <typename U, typename MP>
Expand Down Expand Up @@ -77,7 +102,8 @@ class box
*/
template <typename Arg,
typename Enable = std::enable_if_t<
!std::is_same<box, std::decay_t<Arg>>::value>>
!std::is_same<box, std::decay_t<Arg>>::value &&
!detail::is_array_impl_v<Arg>>>
box(Arg&& arg)
: impl_{detail::make<heap, holder>(std::forward<Arg>(arg))}
{
Expand Down