mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix type_traits implementation
This commit is contained in:
parent
bd2194e331
commit
ef073dbdbb
7 changed files with 111 additions and 6 deletions
|
@ -85,7 +85,7 @@ namespace sprout {
|
|||
{};
|
||||
template<typename From, typename To>
|
||||
struct is_const_iterator_cast_convertible<From*, To*>
|
||||
: public sprout::is_same<typename std::remove_const<From>::type, typename std::remove_const<To>::type>
|
||||
: public sprout::is_same<typename std::remove_cv<From>::type, typename std::remove_cv<To>::type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
|
@ -133,4 +133,54 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
//
|
||||
// note:
|
||||
// const_iterator_cast is an adaptable function for interconversion
|
||||
// with iterator and const_iterator.
|
||||
// If you want to adapt a user-defined iterator class to const_iterator_cast:
|
||||
// - Specialize sprout::is_const_iterator_cast_convertible.
|
||||
// - Overload const_iterator_conversion as to be lookup in the ADL.
|
||||
//
|
||||
// example:
|
||||
// #include <type_traits>
|
||||
// #include <sprout/config.hpp>
|
||||
// #include <sprout/type_traits.hpp>
|
||||
// #include <sprout/iterator/const_iterator_cast.hpp>
|
||||
// /* Mylib::Iterator is an user-defined iterator class*/
|
||||
// namespace Mylib {
|
||||
// template<typename T>
|
||||
// struct Iterator {
|
||||
// T* p;
|
||||
// typedef T* pointer;
|
||||
// /* definition iterator interface... */
|
||||
// };
|
||||
// }
|
||||
// /* const_iterator_cast adapt for Mylib::Iterator */
|
||||
// namespace sprout {
|
||||
// template<typename From, typename To>
|
||||
// struct is_const_iterator_cast_convertible<
|
||||
// Mylib::Iterator<From>,
|
||||
// Mylib::Iterator<To>
|
||||
// >
|
||||
// : public sprout::is_same<
|
||||
// typename std::remove_cv<From>::type,
|
||||
// typename std::remove_cv<To>::type
|
||||
// >
|
||||
// {};
|
||||
// }
|
||||
// namespace Mylib {
|
||||
// template<typename To, typename From>
|
||||
// inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
// sprout::is_const_iterator_cast_convertible<Iterator<From>, To>::value,
|
||||
// To
|
||||
// >::type
|
||||
// const_iterator_conversion(Iterator<From> const& it) {
|
||||
// return To{const_cast<typename To::pointer>(it.p)};
|
||||
// }
|
||||
// }
|
||||
// /* test const_iterator_cast with Mylib::Iterator */
|
||||
// constexpr Mylib::Iterator<int const> it{0};
|
||||
// static_assert(sprout::const_iterator_cast<Mylib::Iterator<int> >(it).p == 0, "");
|
||||
//
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_CONST_ITERATOR_CAST_HPP
|
||||
|
|
|
@ -189,4 +189,54 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
//
|
||||
// note:
|
||||
// const_reference_cast is an adaptable function for interconversion
|
||||
// with reference and const_reference.
|
||||
// If you want to adapt a user-defined reference proxy class to const_reference_cast:
|
||||
// - Specialize sprout::is_const_reference_cast_convertible.
|
||||
// - Overload const_reference_conversion as to be lookup in the ADL.
|
||||
//
|
||||
// example:
|
||||
// #include <type_traits>
|
||||
// #include <sprout/config.hpp>
|
||||
// #include <sprout/type_traits.hpp>
|
||||
// #include <sprout/iterator/const_reference_cast.hpp>
|
||||
// /* Mylib::Reference is an user-defined reference proxy class*/
|
||||
// namespace Mylib {
|
||||
// template<typename T>
|
||||
// struct Reference {
|
||||
// T* p;
|
||||
// typedef T* pointer;
|
||||
// /* definition reference proxy interface... */
|
||||
// };
|
||||
// }
|
||||
// /* const_reference_cast adapt for Mylib::Reference */
|
||||
// namespace sprout {
|
||||
// template<typename From, typename To>
|
||||
// struct is_const_reference_cast_convertible<
|
||||
// Mylib::Reference<From>,
|
||||
// Mylib::Reference<To>
|
||||
// >
|
||||
// : public sprout::is_same<
|
||||
// typename std::remove_cv<From>::type,
|
||||
// typename std::remove_cv<To>::type
|
||||
// >
|
||||
// {};
|
||||
// }
|
||||
// namespace Mylib {
|
||||
// template<typename To, typename From>
|
||||
// inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
// sprout::is_const_reference_cast_convertible<Reference<From>, To>::value,
|
||||
// To
|
||||
// >::type
|
||||
// const_reference_conversion(Reference<From> const& it) {
|
||||
// return To{const_cast<typename To::pointer>(it.p)};
|
||||
// }
|
||||
// }
|
||||
// /* test const_reference_cast with Mylib::Reference */
|
||||
// constexpr Mylib::Reference<int const> it{0};
|
||||
// static_assert(sprout::const_reference_cast<Mylib::Reference<int> >(it).p == 0, "");
|
||||
//
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_CONST_REFERENCE_CAST_HPP
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/is_same.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/functional/subscript.hpp>
|
||||
|
@ -294,7 +295,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename FromContainer, typename ToContainer, bool C, typename Subscript>
|
||||
struct is_const_iterator_cast_convertible<sprout::index_iterator<FromContainer, C, Subscript>, sprout::index_iterator<ToContainer, C, Subscript> >
|
||||
: public std::is_same<typename std::decay<FromContainer>::type, typename std::decay<ToContainer>::type>
|
||||
: public sprout::is_same<typename std::decay<FromContainer>::type, typename std::decay<ToContainer>::type>
|
||||
{};
|
||||
//
|
||||
// const_iterator_conversion
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/is_assignable.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -23,7 +24,7 @@ namespace sprout {
|
|||
{};
|
||||
template<typename T>
|
||||
struct is_copy_assignable_impl<T, false>
|
||||
: public std::is_assignable<T, T const&>
|
||||
: public sprout::is_assignable<T, T const&>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/is_constructible.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -23,7 +24,7 @@ namespace sprout {
|
|||
{};
|
||||
template<typename T>
|
||||
struct is_copy_constructible_impl<T, false>
|
||||
: public std::is_constructible<T, T const&>
|
||||
: public sprout::is_constructible<T, T const&>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/is_assignable.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -23,7 +24,7 @@ namespace sprout {
|
|||
{};
|
||||
template<typename T>
|
||||
struct is_move_assignable_impl<T, false>
|
||||
: public std::is_assignable<T, T&&>
|
||||
: public sprout::is_assignable<T, T&&>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/is_constructible.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -23,7 +24,7 @@ namespace sprout {
|
|||
{};
|
||||
template<typename T>
|
||||
struct is_move_constructible_impl<T, false>
|
||||
: public std::is_constructible<T, T&&>
|
||||
: public sprout::is_constructible<T, T&&>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
|
|
Loading…
Reference in a new issue