#ifndef ORIGIN_VECTOR_GROW_HPP #define ORIGIN_VECTOR_GROW_HPP namespace origin { namespace vector_ { // TODO: Rewrite the grow strategy so that it is actually responsible for the // reallocation, moving, and construction of vectors. /** * The never grow strategy will guarantee a static-sized vector. * @todo Shoud this grown an exception or invoke some other error handler? */ struct grow_never { template typename Vector::size_type operator()(Vector const& v, typename Vector::size_type) const { raise_length_error("grow_never", Vector::get_length_error()); } }; /** * The linear strategy will cause the growth the vector to be linear with * respect to the number of elements requested. This growth strategy */ struct grow_linear { template typename Vector::size_type operator()(Vector const& v, typename Vector::size_type req) const { return v.size() + req; } }; /** * The times_two strategy will cause the vector to grow exponentially with * a growth base of N. By default N == 2, and the size of the vector is doubled * when full. */ template struct grow_exponential { template typename Vector::size_type operator()(Vector const& v, typename Vector::size_type n) const { return v.size() + ((N - 1) * std::max(v.size(), n)); } }; /** * @requires GrowStrategy */ struct grow_policy { }; template > struct grow { typedef grow_policy policy_kind; typedef Strategy type; // Aliases for common policies. typedef grow never; typedef grow linear; typedef grow> doubling; }; template class extract_grow { typedef policy_element element; public: typedef typename mpl::if_< std::is_same, Default, typename element::type >::type type; }; } } // namespace origin::vector_ #endif