mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue