add const_iterator_cast

This commit is contained in:
bolero-MURAKAMI 2014-01-05 22:20:27 +09:00
parent be0bc155d8
commit cd72873c3a
7 changed files with 175 additions and 8 deletions

View file

@ -25,7 +25,7 @@ namespace sprout {
make_array(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{T(sprout::forward<Types>(args))...}};
}
// !!!
// !!! OLD:
// template<typename... Types>
// inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
// make_array(Types&&... args) {

View file

@ -167,7 +167,7 @@ namespace sprout {
64,
bit_count_ + 64 * 8
)
// !!!
// !!! TEMP:
// : process<D + 1>(
// h_,
// sprout::make_array<std::uint8_t>(args...),
@ -192,7 +192,7 @@ namespace sprout {
bit_count_ + sizeof...(Args) * 8
)
: block_byte_index_ + sizeof...(Args) == 64
// !!!
// !!! TEMP:
// ? process<D + 1>(
// h_,
// sprout::get_internal(sprout::range::fixed::copy(sprout::make_array<std::uint8_t>(args...), sprout::sub(block_, block_byte_index_))),

View file

@ -72,9 +72,9 @@ namespace sprout {
? sprout::darkroom::rays::point_of_intersection(ray, distance)
: position_type(0, 0, 0)
,
normal_,//hit_side > 0 ? normal_ : sprout::darkroom::coords::negate(normal_),
normal_,// !!! TEMP: hit_side > 0 ? normal_ : sprout::darkroom::coords::negate(normal_),
sprout::darkroom::materials::calculate_material(mat_, unit_type(0), unit_type(0)), // ???
false // !!! is_from_inside
false // !!! TEMP: is_from_inside
);
}
template<typename Ray>

View file

@ -0,0 +1,144 @@
/*=============================================================================
Copyright (c) 2011-2013 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_ITERATOR_CONST_ITERATOR_CAST_HPP
#define SPROUT_ITERATOR_CONST_ITERATOR_CAST_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout {
//
// is_const_iterator_cast_convertible
//
template<typename From, typename To>
struct is_const_iterator_cast_convertible
: public sprout::false_type
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From, To const>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From, To volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From, To const volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const, To>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const, To const>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const, To volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const, To const volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From volatile, To>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From volatile, To const>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From volatile, To volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From volatile, To const volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const volatile, To>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const volatile, To const>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const volatile, To volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From const volatile, To const volatile>
: public sprout::is_const_iterator_cast_convertible<From, To>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From*, To*>
: public std::is_same<typename std::remove_const<From>::type, typename std::remove_const<To>::type>
{};
// //
// // pointer_add_const
// //
// template<typename T>
// struct pointer_add_const
// : public std::add_const<T>
// {};
// template<typename T>
// struct pointer_add_const<T*>
// : public sprout::identity<typename std::add_const<T>::type*>
// {};
} // namespace sprout
namespace sprout_adl {
template<typename To>
sprout::not_found_via_adl const_iterator_conversion(...);
} // namespace sprout_adl
namespace sprout {
namespace iterator_detail {
template<
typename T,
typename U,
typename sprout::enabler_if<sprout::is_const_iterator_cast_convertible<U*, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR T
const_iterator_conversion(U* it) {
return const_cast<T>(it);
}
} // namespace iterator_detail
} // namespace sprout
namespace sprout_iterator_detail {
template<typename To, typename From>
inline SPROUT_CONSTEXPR To
const_iterator_cast(From const& it) {
using sprout::iterator_detail::const_iterator_conversion;
using sprout_adl::const_iterator_conversion;
return const_iterator_conversion<To>(it);
}
} // namespace sprout_iterator_detail
namespace sprout {
//
// const_iterator_cast
//
template<typename To, typename From>
inline SPROUT_CONSTEXPR To
const_iterator_cast(From const& it) {
return sprout_iterator_detail::const_iterator_cast<To>(it);
}
} // namespace sprout
#endif // #ifndef SPROUT_ITERATOR_CONST_ITERATOR_CAST_HPP

View file

@ -16,10 +16,13 @@
#include <sprout/iterator/next.hpp>
#include <sprout/iterator/prev.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/iterator/const_iterator_cast.hpp>
#include <sprout/iterator/detail/iterator_to_pointer.hpp>
#include <sprout/utility/value_holder/value_holder.hpp>
#include <sprout/utility/swap.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
//
@ -283,6 +286,26 @@ namespace sprout {
iterator_prev(sprout::index_iterator<Container, C> const& it) {
return it.prev();
}
//
// is_const_iterator_cast_convertible
//
template<typename FromContainer, typename ToContainer, bool C>
struct is_const_iterator_cast_convertible<sprout::index_iterator<FromContainer, C>, sprout::index_iterator<ToContainer, C> >
: public std::is_same<typename std::decay<FromContainer>::type, typename std::decay<ToContainer>::type>
{};
//
// const_iterator_conversion
//
template<
typename T,
typename Container, bool C,
typename sprout::enabler_if<sprout::is_const_iterator_cast_convertible<sprout::index_iterator<Container, C>, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR T
const_iterator_conversion(sprout::index_iterator<Container, C> const& it) {
return T(const_cast<typename T::container_type>(it.base()), it.index());
}
} // namespace sprout
#endif // #ifndef SPROUT_ITERATOR_INDEX_ITERATOR_HPP

View file

@ -60,7 +60,7 @@ namespace sprout {
);
}
// !!!
// !!! OLD:
// template<typename T>
// inline SPROUT_CONSTEXPR T
// cos_impl_2(T x) {

View file

@ -120,7 +120,7 @@ namespace sprout {
: init(true)
, val(v)
{}
// !!! for T const&
// !!! TEMP: for T const&
// SPROUT_CONSTEXPR optional(T&& v)
// : init(true)
// , val(sprout::move(v))
@ -145,7 +145,7 @@ namespace sprout {
: init(cond)
, val(cond ? holder_type(v) : holder_type())
{}
// !!! for T const&
// !!! TEMP: for T const&
// SPROUT_CONSTEXPR optional(bool cond, T&& v)
// : init(cond)
// , val(cond ? holder_type(sprout::move(v)) : holder_type())