region: add cast function

This commit is contained in:
Danny Robson 2015-09-21 15:33:58 +10:00
parent 2469450ea9
commit bcaa6c7428
3 changed files with 40 additions and 0 deletions

View File

@ -214,6 +214,7 @@ UTIL_FILES = \
ray.hpp \ ray.hpp \
region.cpp \ region.cpp \
region.hpp \ region.hpp \
region.ipp \
si.cpp \ si.cpp \
signal.cpp \ signal.cpp \
signal.hpp \ signal.hpp \

View File

@ -67,6 +67,10 @@ namespace util {
region (point_t, point_t); region (point_t, point_t);
explicit region (std::array<T,S*2>); explicit region (std::array<T,S*2>);
//---------------------------------------------------------------------
template <typename U>
constexpr region<S,U> cast (void) const;
//--------------------------------------------------------------------- //---------------------------------------------------------------------
size_type area (void) const; size_type area (void) const;
size_type diameter (void) const; size_type diameter (void) const;
@ -133,4 +137,6 @@ namespace util {
std::ostream& operator<< (std::ostream&, const util::region<S,T>&); std::ostream& operator<< (std::ostream&, const util::region<S,T>&);
} }
#include "region.ipp"
#endif #endif

33
region.ipp Normal file
View File

@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2010-2015 Danny Robson <danny@nerdcruft.net>
*/
#ifdef __UTIL_REGION_IPP
#error
#endif
#define __UTIL_REGION_IPP
namespace util {
template <size_t S, typename T>
template <typename U>
constexpr region<S,U>
region<S,T>::cast (void) const
{
return {
p.template cast<typename region<S,U>::position_type> (),
e.template cast<typename region<S,U>::size_type> ()
};
}
}