/* * 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 2012-2015 Danny Robson */ #ifndef __UTIL_COORD_BASE_HPP #define __UTIL_COORD_BASE_HPP #include "init.hpp" #include "../maths.hpp" #include #include namespace util { namespace coord { ///////////////////////////////////////////////////////////////////////// template class KLASS, typename ...tags> struct base : public init { static_assert (S > 0, "coord dimensions must be strictly positive"); typedef T value_type; static constexpr size_t dimension = S; static constexpr size_t elements = S; size_t size (void) const { return S; } // constructors using init::init; base () = default; constexpr explicit base (T val) { std::fill (std::begin (this->data), std::end (this->data), val); } constexpr explicit base (const base &rhs) = default; base& operator= (const base &rhs) = default; // element accessors T& operator[] (size_t i) { return this->data[i]; } T operator[] (size_t i) const { return this->data[i]; } const T* begin (void) const { return std::begin (this->data); } const T* end (void) const { return std::end (this->data); } T* begin (void) { return std::begin (this->data); } T* end (void) { return std::end (this->data); } /////////////////////////////////////////////////////////////////////// // conversions template