add pointer_cast

This commit is contained in:
bolero-MURAKAMI 2014-11-28 16:19:07 +09:00
parent 897d1e25b6
commit fbb95d9068
36 changed files with 553 additions and 72 deletions

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_COMPLEX_OPERATORS_HPP
#define SPROUT_COMPLEX_OPERATORS_HPP
#include <iosfwd>
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/complex/complex.hpp>

View file

@ -13,6 +13,7 @@
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp>
#include <sprout/functional/base.hpp>
@ -235,20 +236,17 @@ namespace sprout {
// unwrap_reference
//
template<typename T>
struct unwrap_reference {
public:
typedef T type;
};
struct unwrap_reference
: public sprout::identity<T>
{};
template<typename T>
struct unwrap_reference<sprout::reference_wrapper<T> > {
public:
typedef T type;
};
struct unwrap_reference<sprout::reference_wrapper<T> >
: public sprout::identity<T>
{};
template<typename T>
struct unwrap_reference<std::reference_wrapper<T> > {
public:
typedef T type;
};
struct unwrap_reference<std::reference_wrapper<T> >
: public sprout::identity<T>
{};
template<typename T>
struct unwrap_reference<T const>
: public sprout::unwrap_reference<T>
@ -266,20 +264,17 @@ namespace sprout {
// strip_reference
//
template<typename T>
struct strip_reference {
public:
typedef T type;
};
struct strip_reference
: public sprout::identity<T>
{};
template<typename T>
struct strip_reference<sprout::reference_wrapper<T> > {
public:
typedef T& type;
};
struct strip_reference<sprout::reference_wrapper<T> >
: public sprout::identity<T&>
{};
template<typename T>
struct strip_reference<std::reference_wrapper<T> > {
public:
typedef T& type;
};
struct strip_reference<std::reference_wrapper<T> >
: public sprout::identity<T&>
{};
template<typename T>
struct strip_reference<T const>
: public sprout::strip_reference<T>

View file

@ -10,8 +10,8 @@
#include <locale>
#include <string>
#include <iosfwd>
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/utility/noncopyable.hpp>
#include <sprout/logic/tribool/tribool.hpp>

View file

@ -11,5 +11,8 @@
#include <sprout/config.hpp>
#include <sprout/memory/addressof.hpp>
#include <sprout/memory/exempt_ptr.hpp>
#include <sprout/memory/observer_ptr.hpp>
#include <sprout/memory/pointer_cast.hpp>
#include <sprout/memory/get_pointer.hpp>
#endif // #ifndef SPROUT_MEMORY_HPP

View file

@ -12,9 +12,14 @@
#include <iterator>
#include <type_traits>
#include <utility>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/functional/hash.hpp>
#include <sprout/functional/less.hpp>
#include <sprout/type_traits/common_decay.hpp>
#include <sprout/memory/pointer_cast.hpp>
#include <sprout/memory/get_pointer.hpp>
namespace sprout {
//
@ -100,10 +105,7 @@ namespace sprout {
SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator bool() const SPROUT_NOEXCEPT {
return get();
}
SPROUT_CONSTEXPR operator pointer() SPROUT_NOEXCEPT {
return get();
}
SPROUT_CONSTEXPR operator const_pointer() const SPROUT_NOEXCEPT {
SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator pointer() const SPROUT_NOEXCEPT {
return get();
}
SPROUT_CXX14_CONSTEXPR pointer
@ -186,25 +188,27 @@ namespace sprout {
operator!=(sprout::exempt_ptr<T> const& x, sprout::exempt_ptr<U> const& y) SPROUT_NOEXCEPT {
return !(x == y);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator==(sprout::exempt_ptr<T> const& x, std::nullptr_t y) SPROUT_NOEXCEPT {
return x.get() == y;
operator==(sprout::exempt_ptr<T> const& x, std::nullptr_t) SPROUT_NOEXCEPT {
return !x;
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::exempt_ptr<T> const& x, std::nullptr_t y) SPROUT_NOEXCEPT {
return !(x == y);
operator!=(sprout::exempt_ptr<T> const& x, std::nullptr_t) SPROUT_NOEXCEPT {
return static_cast<bool>(x);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator==(std::nullptr_t, sprout::exempt_ptr<T> const& y) SPROUT_NOEXCEPT {
return !y;
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator==(std::nullptr_t x, sprout::exempt_ptr<T> const& y) SPROUT_NOEXCEPT {
return x == y.get();
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator!=(std::nullptr_t x, sprout::exempt_ptr<T> const& y) SPROUT_NOEXCEPT {
return !(x == y);
operator!=(std::nullptr_t, sprout::exempt_ptr<T> const& y) SPROUT_NOEXCEPT {
return static_cast<bool>(y);
}
//
// operator<
@ -215,7 +219,8 @@ namespace sprout {
template<typename T, typename U>
inline SPROUT_CONSTEXPR bool
operator<(sprout::exempt_ptr<T> const& x, sprout::exempt_ptr<U> const& y) {
return x.get() < y.get();
typedef typename sprout::common_decay<T*, U*>::type type;
return sprout::less<type>()(x.get(), y.get());
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR bool
@ -232,6 +237,48 @@ namespace sprout {
operator>=(sprout::exempt_ptr<T> const& x, sprout::exempt_ptr<U> const& y) {
return !(x < y);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<(sprout::exempt_ptr<T> const& x, std::nullptr_t y) {
return sprout::less<T*>()(x.get(), y);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>(sprout::exempt_ptr<T> const& x, std::nullptr_t y) {
return y < x;
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::exempt_ptr<T> const& x, std::nullptr_t y) {
return !(y < x);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::exempt_ptr<T> const& x, std::nullptr_t y) {
return !(x < y);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<(std::nullptr_t x, sprout::exempt_ptr<T> const& y) {
return sprout::less<T*>()(x, y.get());
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>(std::nullptr_t x, sprout::exempt_ptr<T> const& y) {
return y < x;
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<=(std::nullptr_t x, sprout::exempt_ptr<T> const& y) {
return !(y < x);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>=(std::nullptr_t x, sprout::exempt_ptr<T> const& y) {
return !(x < y);
}
//
// operator+
// operator-
@ -246,6 +293,14 @@ namespace sprout {
operator-(sprout::exempt_ptr<T> const& x, sprout::exempt_ptr<T> const& y) {
return x.get() - y.get();
}
//
// operator<<
//
template<typename T, typename Elem, typename Traits>
inline SPROUT_CONSTEXPR std::basic_ostream<Elem, Traits>&
operator<<(std::basic_ostream<Elem, Traits>& lhs, sprout::exempt_ptr<T> const& rhs) {
return lhs << rhs.get();
}
} // namespace sprout
namespace sprout {
@ -276,4 +331,46 @@ namespace std {
#endif
} // namespace std
namespace sprout {
//
// static_pointer_cast
// const_pointer_cast
// dynamic_pointer_cast
// reinterpret_pointer_cast
//
template<typename T, typename U>
inline SPROUT_CONSTEXPR sprout::exempt_ptr<T>
static_pointer_cast(sprout::exempt_ptr<U> const& p) {
typedef typename sprout::exempt_ptr<T>::element_type element_type;
return sprout::exempt_ptr<T>(sprout::static_pointer_cast<element_type>(p.get()));
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR sprout::exempt_ptr<T>
const_pointer_cast(sprout::exempt_ptr<U> const& p) {
typedef typename sprout::exempt_ptr<T>::element_type element_type;
return sprout::exempt_ptr<T>(sprout::const_pointer_cast<element_type>(p.get()));
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR sprout::exempt_ptr<T>
dynamic_pointer_cast(sprout::exempt_ptr<U> const& p) {
typedef typename sprout::exempt_ptr<T>::element_type element_type;
return sprout::exempt_ptr<T>(sprout::dynamic_pointer_cast<element_type>(p.get()));
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR sprout::exempt_ptr<T>
reinterpret_pointer_cast(sprout::exempt_ptr<U> const& p) {
typedef typename sprout::exempt_ptr<T>::element_type element_type;
return sprout::exempt_ptr<T>(sprout::reinterpret_pointer_cast<element_type>(p.get()));
}
//
// get_pointer
//
template<typename T>
inline SPROUT_NON_CONSTEXPR T*
get_pointer(sprout::exempt_ptr<T> const& p) SPROUT_NOEXCEPT {
return p.get();
}
} // namespace sprout
#endif // #ifndef SPROUT_MEMORY_EXEMPT_PTR_HPP

View file

@ -0,0 +1,46 @@
/*=============================================================================
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_MEMORY_GET_POINTER_HPP
#define SPROUT_MEMORY_GET_POINTER_HPP
#include <memory>
#include <sprout/config.hpp>
namespace sprout {
//
// get_pointer
//
template<typename T>
inline SPROUT_CONSTEXPR T*
get_pointer(T* p) SPROUT_NOEXCEPT {
return p;
}
template<typename T>
inline SPROUT_NON_CONSTEXPR T*
get_pointer(std::auto_ptr<T> const& p) SPROUT_NOEXCEPT {
return p.get();
}
#if !defined(SPROUT_NO_CXX11_SMART_PTR)
template<typename T>
inline SPROUT_NON_CONSTEXPR T*
get_pointer(std::unique_ptr<T> const& p) SPROUT_NOEXCEPT {
return p.get();
}
template<typename T>
inline SPROUT_NON_CONSTEXPR T*
get_pointer(std::shared_ptr<T> const& p) SPROUT_NOEXCEPT {
return p.get();
}
#endif
} // namespace sprout
#endif // #ifndef SPROUT_MEMORY_GET_POINTER_HPP

View file

@ -0,0 +1,33 @@
/*=============================================================================
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_MEMORY_OBSERVER_PTR_HPP
#define SPROUT_MEMORY_OBSERVER_PTR_HPP
#include <sprout/config.hpp>
#include <sprout/memory/exempt_ptr.hpp>
namespace sprout {
//
// make_observer
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::exempt_ptr<T>
make_observer(T* p) SPROUT_NOEXCEPT {
return sprout::exempt_ptr<T>(p);
}
#if SPROUT_USE_TEMPLATE_ALIASES
//
// observer_ptr
//
template<typename T>
using observer_ptr = sprout::exempt_ptr<T>;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_MEMORY_OBSERVER_PTR_HPP

View file

@ -0,0 +1,69 @@
/*=============================================================================
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_MEMORY_POINTER_CAST_HPP
#define SPROUT_MEMORY_POINTER_CAST_HPP
#include <memory>
#include <sprout/config.hpp>
#include <sprout/utility/dyn_cast.hpp>
#include <sprout/utility/reinter_cast.hpp>
namespace sprout {
//
// static_pointer_cast
// const_pointer_cast
// dynamic_pointer_cast
// reinterpret_pointer_cast
//
template<typename T, typename U>
inline SPROUT_CONSTEXPR T*
static_pointer_cast(U* p) {
return static_cast<T*>(p);
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR T*
const_pointer_cast(U* p) {
return const_cast<T*>(p);
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR T*
dynamic_pointer_cast(U* p) {
return sprout::dyn_cast<T*>(p);
}
template<typename T, typename U>
inline SPROUT_CONSTEXPR T*
reinterpret_pointer_cast(U* p) {
return sprout::reinter_cast<T*>(p);
}
#if !defined(SPROUT_NO_CXX11_SMART_PTR)
template<typename T, typename U>
inline SPROUT_NON_CONSTEXPR std::shared_ptr<T>
static_pointer_cast(std::shared_ptr<U> const& p) {
return std::static_pointer_cast<T>(p);
}
template<typename T, typename U>
inline SPROUT_NON_CONSTEXPR std::shared_ptr<T>
const_pointer_cast(std::shared_ptr<U> const& p) {
return std::const_pointer_cast<T>(p);
}
template<typename T, typename U>
inline SPROUT_NON_CONSTEXPR std::shared_ptr<T>
dynamic_pointer_cast(std::shared_ptr<U> const& p) {
return std::dynamic_pointer_cast<T>(p);
}
template<typename T, typename U>
inline SPROUT_NON_CONSTEXPR std::shared_ptr<T>
reinterpret_pointer_cast(std::shared_ptr<U> const& p) {
typedef typename std::shared_ptr<T>::element_type element_type;
return std::shared_ptr<T>(p, reinterpret_cast<element_type*>(p.get()));
}
#endif
} // namespace sprout
#endif // #ifndef SPROUT_MEMORY_POINTER_CAST_HPP

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_OPTIONAL_IO_HPP
#define SPROUT_OPTIONAL_IO_HPP
#include <iosfwd>
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/optional/optional.hpp>
#include <sprout/none.hpp>

View file

@ -9,8 +9,8 @@
#define SPROUT_RANDOM_ADDITIVE_COMBINE_HPP
#include <cstdint>
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/random/linear_congruential.hpp>

View file

@ -8,7 +8,8 @@
#ifndef SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#define SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>
#include <sprout/math/log.hpp>

View file

@ -9,7 +9,8 @@
#define SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
#include <cstdint>
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>

View file

@ -9,7 +9,8 @@
#define SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP
#include <cstdint>
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>

View file

@ -8,7 +8,8 @@
#ifndef SPROUT_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
#define SPROUT_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/detail/integer/integer_mask.hpp>
#include <sprout/random/detail/seed_impl.hpp>

View file

@ -8,7 +8,8 @@
#ifndef SPROUT_RANDOM_MERSENNE_TWISTER_HPP
#define SPROUT_RANDOM_MERSENNE_TWISTER_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
#define SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>
#include <sprout/math/constants.hpp>

View file

@ -9,8 +9,8 @@
#define SPROUT_RANDOM_SHUFFLE_ORDER_HPP
#include <cstdint>
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#define SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#define SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp>

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_RANDOM_XOR_COMBINE_HPP
#define SPROUT_RANDOM_XOR_COMBINE_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/random/type_traits.hpp>

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_RATIONAL_IO_HPP
#define SPROUT_RATIONAL_IO_HPP
#include <ios>
#include <iostream>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/rational/rational.hpp>
#include <sprout/detail/io/ios_state.hpp>

View file

@ -8,7 +8,8 @@
#ifndef SPROUT_STRING_IO_HPP
#define SPROUT_STRING_IO_HPP
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/string/string.hpp>

View file

@ -18,6 +18,8 @@
#include <sprout/type_traits/is_uint.hpp>
#include <sprout/type_traits/is_char_type.hpp>
#include <sprout/type_traits/is_c_str.hpp>
#include <sprout/type_traits/is_nullptr_cast.hpp>
#include <sprout/type_traits/is_upcast.hpp>
#include <sprout/type_traits/has_type.hpp>
#include <sprout/type_traits/has_value.hpp>
#include <sprout/type_traits/identity.hpp>

View file

@ -0,0 +1,29 @@
/*=============================================================================
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_TYPE_TRAITS_IS_NULLPTR_CAST_HPP
#define SPROUT_TYPE_TRAITS_IS_NULLPTR_CAST_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
namespace sprout {
//
// is_nullptr_cast
//
template<typename From, typename To>
struct is_nullptr_cast
: public sprout::integral_constant<
bool,
sprout::is_pointer<To>::value && sprout::is_same<typename sprout::decay<From>::type, std::nullptr_t>::value
>
{};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NULLPTR_CAST_HPP

View file

@ -0,0 +1,35 @@
/*=============================================================================
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_TYPE_TRAITS_IS_UPCAST_HPP
#define SPROUT_TYPE_TRAITS_IS_UPCAST_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
#include <sprout/type_traits/is_nullptr_cast.hpp>
namespace sprout {
//
// is_upcast
//
template<typename From, typename To>
struct is_upcast
: public sprout::integral_constant<
bool,
sprout::is_nullptr_cast<From, To>::value
|| (sprout::is_pointer<To>::value
&& sprout::is_base_of<typename sprout::remove_pointer<To>::type, typename sprout::remove_pointer<typename sprout::decay<From>::type>::type>::value
)
|| (sprout::is_reference<To>::value
&& sprout::is_base_of<typename sprout::remove_reference<To>::type, typename sprout::remove_reference<From>::type>::value
)
>
{};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_UPCAST_HPP

View file

@ -12,6 +12,7 @@
#include <sprout/utility/pair.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/utility/operation_ext.hpp>
#include <sprout/utility/cast.hpp>
#include <sprout/utility/noncopyable.hpp>
#include <sprout/utility/enabler_if.hpp>
#include <sprout/utility/pack.hpp>

22
sprout/utility/cast.hpp Normal file
View 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_CAST_HPP
#define SPROUT_UTILITY_CAST_HPP
#include <sprout/config.hpp>
#include <sprout/utility/as_lvalue.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/utility/unmove.hpp>
#include <sprout/utility/pass_through.hpp>
#include <sprout/utility/implicit_cast.hpp>
#include <sprout/utility/upcast.hpp>
#include <sprout/utility/dyn_cast.hpp>
#include <sprout/utility/reinter_cast.hpp>
#endif // #ifndef SPROUT_UTILITY_CAST_HPP

View file

@ -0,0 +1,38 @@
/*=============================================================================
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_DYN_CAST_HPP
#define SPROUT_UTILITY_DYN_CAST_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/is_upcast.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
//
// dyn_cast
//
template<
typename T, typename U,
typename sprout::enabler_if<sprout::is_upcast<U&&, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR T
dyn_cast(U&& x) {
return static_cast<T>(SPROUT_FORWARD(U, x));
}
template<
typename T, typename U,
typename sprout::enabler_if<!sprout::is_upcast<U&&, T>::value>::type = sprout::enabler
>
inline SPROUT_NON_CONSTEXPR T
dyn_cast(U&& x) {
return dynamic_cast<T>(SPROUT_FORWARD(U, x));
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_DYN_CAST_HPP

View file

@ -0,0 +1,25 @@
/*=============================================================================
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_IMPLICIT_CAST_HPP
#define SPROUT_UTILITY_IMPLICIT_CAST_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
//
// implicit_cast
//
template<typename T>
inline SPROUT_CONSTEXPR T
implicit_cast (typename sprout::identity<T>::type t) {
return t;
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_IMPLICIT_CAST_HPP

View file

@ -11,7 +11,7 @@
#include <sprout/config.hpp>
namespace sprout {
namespace noncopyable_ {
namespace noncopyable_detail {
class noncopyable {
protected:
SPROUT_CONSTEXPR noncopyable() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL
@ -20,11 +20,11 @@ namespace sprout {
noncopyable(noncopyable const&) SPROUT_DELETED_FUNCTION_DECL
noncopyable& operator=(noncopyable const&) SPROUT_DELETED_FUNCTION_DECL
};
} // namespace noncopyable_
} // namespace noncopyable_detail
//
// noncopyable
//
typedef sprout::noncopyable_::noncopyable noncopyable;
typedef sprout::noncopyable_detail::noncopyable noncopyable;
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_NONCOPYABLE_HPP

View file

@ -14,7 +14,5 @@
#include <sprout/utility/move.hpp>
#include <sprout/utility/swap.hpp>
#include <sprout/utility/exchange.hpp>
#include <sprout/utility/unmove.hpp>
#include <sprout/utility/eat.hpp>
#endif // #ifndef SPROUT_UTILITY_OPERATION_HPP

View file

@ -10,10 +10,7 @@
#include <sprout/config.hpp>
#include <sprout/utility/compare_pointees.hpp>
#include <sprout/utility/as_lvalue.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/utility/pass_through.hpp>
#include <sprout/utility/eat.hpp>
#include <sprout/utility/limited.hpp>
#endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP

View file

@ -0,0 +1,55 @@
/*=============================================================================
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_REINTER_CAST_HPP
#define SPROUT_UTILITY_REINTER_CAST_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
namespace detail {
template<typename From, typename To>
struct is_same_reinterpret_cast
: public sprout::integral_constant<
bool,
(sprout::is_reference<To>::value
&& sprout::is_same<typename sprout::decay<From>::type, typename sprout::decay<To>::type>::value
&& sprout::is_convertible<From, To>::value
)
|| ((sprout::is_integral<To>::type || sprout::is_enum<To>::type || sprout::is_pointer<To>::type)
&& sprout::is_same<typename sprout::decay<From>::type, To>::value
)
>
{};
} // namespace detail
//
// reinter_cast
//
template<
typename T, typename U,
typename sprout::enabler_if<sprout::detail::is_same_reinterpret_cast<U&&, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR T
reinter_cast(U&& x) {
return SPROUT_FORWARD(U, x);
}
template<
typename T, typename U,
typename sprout::enabler_if<!sprout::detail::is_same_reinterpret_cast<U&&, T>::value>::type = sprout::enabler
>
inline SPROUT_NON_CONSTEXPR T
reinter_cast(U&& x) {
return reinterpret_cast<T>(SPROUT_FORWARD(U, x));
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_REINTER_CAST_HPP

View file

@ -9,7 +9,8 @@
#define SPROUT_UTILITY_STRING_IO_HPP
#include <iterator>
#include <ios>
#include <istream>
#include <ostream>
#include <sprout/config.hpp>
#include <sprout/algorithm/cxx14/copy.hpp>
#include <sprout/utility/string_ref/string_ref.hpp>

30
sprout/utility/upcast.hpp Normal file
View file

@ -0,0 +1,30 @@
/*=============================================================================
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_UPCAST_HPP
#define SPROUT_UTILITY_UPCAST_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/is_upcast.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
//
// upcast
//
template<
typename T, typename U,
typename sprout::enabler_if<sprout::is_upcast<U&&, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR T
upcast(U&& x) {
return static_cast<T>(SPROUT_FORWARD(U, x));
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_UPCAST_HPP

View file

@ -9,9 +9,8 @@
#define SPROUT_UUID_IO_HPP
#include <iterator>
#include <ios>
#include <ostream>
#include <istream>
#include <ostream>
#include <locale>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>