diff --git a/src/memory.h b/src/memory.h new file mode 100644 index 00000000..4ee02807 --- /dev/null +++ b/src/memory.h @@ -0,0 +1,98 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +http://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef __ETL_MEMORY__ +#define __ETL_MEMORY__ + +#include + +///\defgroup memory memory +///\ingroup etl +namespace etl +{ + //***************************************************************************** + /// Fills uninitailised memory with N values. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value) + { + return etl::uninitialized_fill(o_begin, o_begin + count, value); + } + + //***************************************************************************** + /// Fills uninitailised memory range with a value. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(&*o_begin))) value_type(value); + ++o_begin; + } + + return o_begin; + } + + //***************************************************************************** + /// Copies N objects to uninitailised memory. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_copy_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin) + { + return etl::uninitialized_copy(i_begin, i_begin + count, o_begin); + } + + //***************************************************************************** + /// Copies a range of objects to uninitailised memory. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) + { + typedef typename std::iterator_traits::value_type value_type; + + while (i_begin != i_end) + { + ::new (static_cast(&*o_begin))) value_type(*i_begin); + ++i_begin + ++o_begin + } + + return o_begin; + } +} + +#endif \ No newline at end of file