Add reserve_vector to libslic3r.h to be globally usable.

This commit is contained in:
tamasmeszaros 2020-08-13 09:00:58 +02:00
parent 7158690ddd
commit add3894e8c
2 changed files with 9 additions and 9 deletions

View File

@ -114,15 +114,6 @@ template<class T> struct remove_cvref
template<class T> using remove_cvref_t = typename remove_cvref<T>::type; template<class T> using remove_cvref_t = typename remove_cvref<T>::type;
template<class T, class I, class... Args> // Arbitrary allocator can be used
inline IntegerOnly<I, std::vector<T, Args...>> reserve_vector(I capacity)
{
std::vector<T, Args...> ret;
if (capacity > I(0)) ret.reserve(size_t(capacity));
return ret;
}
/// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html /// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html
template<class T, class I, class = IntegerOnly<I>> template<class T, class I, class = IntegerOnly<I>>
inline std::vector<T> linspace_vector(const ArithmeticOnly<T> &start, inline std::vector<T> linspace_vector(const ArithmeticOnly<T> &start,

View File

@ -266,6 +266,15 @@ using IteratorOnly = std::enable_if_t<
!std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
>; >;
template<class T, class I, class... Args> // Arbitrary allocator can be used
IntegerOnly<I, std::vector<T, Args...>> reserve_vector(I capacity)
{
std::vector<T, Args...> ret;
if (capacity > I(0)) ret.reserve(size_t(capacity));
return ret;
}
} // namespace Slic3r } // namespace Slic3r
#endif #endif