// // immer: immutable data structures for C++ // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente // // This software is distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt // #pragma once #include #include #include #include #include #include #include #include namespace immer { /*! * Metafunction that returns the best *transience policy* to use for a * given *refcount policy*. */ template struct get_transience_policy : std::conditional::value, gc_transience_policy, no_transience_policy> {}; template using get_transience_policy_t = typename get_transience_policy::type; /*! * Metafunction that returns wether to *prefer fewer bigger objects* * to use for a given *heap policy*. */ template struct get_prefer_fewer_bigger_objects : std::integral_constant< bool, std::is_same>::value> {}; template constexpr auto get_prefer_fewer_bigger_objects_v = get_prefer_fewer_bigger_objects::value; /*! * Metafunction that returns wether to use *transient R-Values* * for a given *refcount policy*. */ template struct get_use_transient_rvalues : std::integral_constant< bool, !std::is_same::value> {}; template constexpr auto get_use_transient_rvalues_v = get_use_transient_rvalues::value; /*! * This is a default implementation of a *memory policy*. A memory * policy is just a bag of other policies plus some flags with hints * to the user about the best way to use these strategies. * * @tparam HeapPolicy A *heap policy*, for example, @ref heap_policy. * @tparam RefcountPolicy A *reference counting policy*, for example, * @ref refcount_policy. * @tparam TransiencePolicy A *transience policy*, for example, * @ref no_transience_policy. * @tparam PreferFewerBiggerObjects Boolean flag indicating whether * the user should prefer to allocate memory in bigger chungs * --e.g. by putting various objects in the same memory * region-- or not. * @tparam UseTransientRValues Boolean flag indicating whether * immutable containers should try to modify contents in-place * when manipulating an r-value reference. */ template , bool PreferFewerBiggerObjects = get_prefer_fewer_bigger_objects_v, bool UseTransientRValues = get_use_transient_rvalues_v> struct memory_policy { using heap = HeapPolicy; using refcount = RefcountPolicy; using transience = TransiencePolicy; static constexpr bool prefer_fewer_bigger_objects = PreferFewerBiggerObjects; static constexpr bool use_transient_rvalues = UseTransientRValues; using transience_t = typename transience::template apply::type; }; /*! * The default *heap policy* just uses the standard heap with a * @ref free_list_heap_policy. If `IMMER_NO_FREE_LIST` is defined to `1` * then it just uses the standard heap. */ #if IMMER_NO_FREE_LIST using default_heap_policy = heap_policy>; #else #if IMMER_NO_THREAD_SAFETY using default_heap_policy = unsafe_free_list_heap_policy; #else using default_heap_policy = free_list_heap_policy; #endif #endif /*! * By default we use thread safe reference counting. */ #if IMMER_NO_THREAD_SAFETY using default_refcount_policy = unsafe_refcount_policy; #else using default_refcount_policy = refcount_policy; #endif /*! * The default memory policy. */ using default_memory_policy = memory_policy; } // namespace immer