mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add shrink_to_fit, unmove
This commit is contained in:
parent
22c3f6e132
commit
ae77da19e1
12 changed files with 192 additions and 45 deletions
|
@ -117,7 +117,7 @@ namespace sprout {
|
|||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline bool
|
||||
inline SPROUT_NON_CONSTEXPR bool
|
||||
assertion_failed_msg(char const* formatted, char const* msg) {
|
||||
return (std::cerr << formatted << ": " << msg << std::endl), std::abort(), false;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ namespace sprout {
|
|||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline bool
|
||||
inline SPROUT_NON_CONSTEXPR bool
|
||||
assertion_failed(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) {
|
||||
return cond ? true
|
||||
: ((void)sprout::assertion_failed(sprout::assertion_info(expr, function, file, line)), false)
|
||||
|
@ -210,7 +210,7 @@ namespace sprout {
|
|||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline bool
|
||||
inline SPROUT_NON_CONSTEXPR bool
|
||||
assertion_failed(char const* formatted) {
|
||||
return (std::cerr << formatted << std::endl), std::abort(), false;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#ifndef SPROUT_COMPLEX_COMPLEX_HPP
|
||||
#define SPROUT_COMPLEX_COMPLEX_HPP
|
||||
|
||||
#include <complex>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
|
||||
|
@ -50,8 +51,12 @@ namespace sprout {
|
|||
: elems_{{re, im}}
|
||||
{}
|
||||
SPROUT_CXX14_CONSTEXPR complex(complex const&) = default;
|
||||
template<typename X>
|
||||
SPROUT_CONSTEXPR complex(complex<X> const& other) SPROUT_NOEXCEPT
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR complex(complex<U> const& other) SPROUT_NOEXCEPT
|
||||
: elems_{{other.real(), other.imag()}}
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR complex(std::complex<U> const& other) SPROUT_NOEXCEPT
|
||||
: elems_{{other.real(), other.imag()}}
|
||||
{}
|
||||
SPROUT_CONSTEXPR T const& real() const SPROUT_NOEXCEPT {
|
||||
|
@ -218,6 +223,11 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR const_pointer c_array() const SPROUT_NOEXCEPT {
|
||||
return elems_.c_array();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator std::complex<U>() const SPROUT_NOEXCEPT {
|
||||
return std::complex<U>(real(), imag());
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::complex<T>::size_type sprout::complex<T>::static_size;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/container/traits_fwd.hpp>
|
||||
#include <sprout/container/container_traits.hpp>
|
||||
|
|
|
@ -14,5 +14,6 @@
|
|||
#include <sprout/container/construct_functions.hpp>
|
||||
#include <sprout/container/fitness_functions.hpp>
|
||||
#include <sprout/container/sub_functions.hpp>
|
||||
#include <sprout/container/shrink_to_fit.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_CONTAINER_FUNCTIONS_HPP
|
||||
|
|
89
sprout/container/shrink_to_fit.hpp
Normal file
89
sprout/container/shrink_to_fit.hpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CONTAINER_SHRINK_TO_FIT_HPP
|
||||
#define SPROUT_CONTAINER_SHRINK_TO_FIT_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
|
||||
namespace sprout_adl {
|
||||
sprout::not_found_via_adl container_shrink_to_fit(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
struct has_mem_shrink_to_fit_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = typename sprout::identity<decltype(std::declval<U>().shrink_to_fit())>::type
|
||||
>
|
||||
static sprout::true_type test(int);
|
||||
static sprout::false_type test(...);
|
||||
};
|
||||
#if defined(_MSC_VER)
|
||||
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::detail::has_mem_shrink_to_fit_test<T>::test(0))>::type>
|
||||
struct has_mem_shrink_to_fit
|
||||
: public Base_
|
||||
{};
|
||||
#else
|
||||
template<typename T>
|
||||
struct has_mem_shrink_to_fit
|
||||
: public sprout::identity<decltype(sprout::detail::has_mem_shrink_to_fit_test<T>::test(0))>::type
|
||||
{};
|
||||
#endif
|
||||
|
||||
template<typename Container>
|
||||
inline SPROUT_CXX14_CONSTEXPR typename std::enable_if<
|
||||
sprout::detail::has_mem_shrink_to_fit<Container&&>::value
|
||||
>::type
|
||||
container_shrink_to_fit_default(Container&& cont) {
|
||||
return SPROUT_FORWARD(Container, cont).shrink_to_fit();
|
||||
}
|
||||
template<typename Container>
|
||||
inline SPROUT_CXX14_CONSTEXPR typename std::enable_if<
|
||||
!sprout::detail::has_mem_shrink_to_fit<Container&&>::value
|
||||
>::type
|
||||
container_shrink_to_fit_default(Container&&) {}
|
||||
} // namespace detail
|
||||
|
||||
namespace container_detail {
|
||||
template<typename Container>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
container_shrink_to_fit(Container&& cont) {
|
||||
return sprout::detail::container_shrink_to_fit_default(SPROUT_FORWARD(Container, cont));
|
||||
}
|
||||
} // namespace container_detail
|
||||
|
||||
//
|
||||
// shrink_to_fit
|
||||
//
|
||||
// effect:
|
||||
// ADL callable container_shrink_to_fit(cont) -> container_shrink_to_fit(cont)
|
||||
// [default]
|
||||
// callable cont.shrink_to_fit() -> cont.shrink_to_fit()
|
||||
// otherwise -> no effects
|
||||
//
|
||||
template<typename Container>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
shrink_to_fit(Container&& cont) {
|
||||
using sprout::container_detail::container_shrink_to_fit;
|
||||
using sprout_adl::container_shrink_to_fit;
|
||||
return container_shrink_to_fit(SPROUT_FORWARD(Container, cont));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/container/container_range_traits.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_CONTAINER_SHRINK_TO_FIT_HPP
|
|
@ -19,7 +19,7 @@ namespace sprout {
|
|||
// operator>>
|
||||
//
|
||||
template<typename Elem, typename Traits, typename T>
|
||||
inline std::basic_istream<Elem, Traits>&
|
||||
inline SPROUT_NON_CONSTEXPR std::basic_istream<Elem, Traits>&
|
||||
operator>>(std::basic_istream<Elem, Traits>& lhs, sprout::optional<T>& rhs) {
|
||||
if (lhs.good()) {
|
||||
int d = lhs.get();
|
||||
|
@ -44,7 +44,7 @@ namespace sprout {
|
|||
// operator<<
|
||||
//
|
||||
template<typename Elem, typename Traits, typename T>
|
||||
inline std::basic_ostream<Elem, Traits>&
|
||||
inline SPROUT_NON_CONSTEXPR std::basic_ostream<Elem, Traits>&
|
||||
operator<<(std::basic_ostream<Elem, Traits>& lhs, sprout::optional<T> const& rhs) {
|
||||
if (lhs.good()) {
|
||||
if (!rhs) {
|
||||
|
|
|
@ -14,5 +14,6 @@
|
|||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/exchange.hpp>
|
||||
#include <sprout/utility/unmove.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_OPERATION_HPP
|
||||
|
|
22
sprout/utility/unmove.hpp
Normal file
22
sprout/utility/unmove.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_UTILITY_UNMOVE_HPP
|
||||
#define SPROUT_UTILITY_UNMOVE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::remove_reference<T>::type&
|
||||
unmove(T&& x) SPROUT_NOEXCEPT {
|
||||
return static_cast<typename std::remove_reference<T>::type&>(x);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_UNMOVE_HPP
|
Loading…
Add table
Add a link
Reference in a new issue