📄 mstl_algorithm_fill.hpp
字号:
/*
The young Library
Copyright (c) 2005 by 杨桓
Permission to use, copy, modify, distribute and sell this software for any
purpose is hereby granted without fee, provided that the above copyright
notice appear in all copies and that both that copyright notice and this
permission notice appear in supporting documentation.
The author make no representations about the suitability of this software
for any purpose. It is provided "as is" without express or implied warranty.
*/
/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_MINI_STL_ALGORITHM_FILL_HEADER_FILE__
#define __MACRO_CPLUSPLUS_MINI_STL_ALGORITHM_FILL_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "../mstl_iterator.hpp"
#include "../mstl_type_traits.hpp"
#include "../string/mstl_char_function.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_BEGIN_NAMESPACE__
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename OutputIterator, typename T >
inline void fill( OutputIterator first, OutputIterator last, const T& value )
{
typedef typename iterator_traits<OutputIterator>::iterator_category cate;
fill_aux( first, last, value, cate() );
}
template< typename OutputIterator, typename T >
void fill_aux( OutputIterator first, OutputIterator last,
const T& value, forward_iterator_tag )
{
for( ; first != last; ++first )
*first = value;
}
template< typename OutputIterator, typename T >
void fill_aux( OutputIterator first, OutputIterator last,
const T& value, random_access_iterator_tag )
{
typedef typename iterator_traits<OutputIterator>::difference_type diff_t;
for( diff_t n = last - first; n > 0; --n,++first )
*first = value;
}
inline void fill( char* first, char* last, const char& value )
{
memset( first, value, (last - first) );
}
inline void fill( signed char* first, signed char* last,
const signed char& value )
{
memset( first, value, (last - first) );
}
inline void fill( unsigned char* first, unsigned char* last,
const unsigned char& value )
{
memset( first, value, (last - first) );
}
inline void fill( wchar_t* first, wchar_t* last, const wchar_t& value )
{
wmemset( first, value, (last - first) );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename OutputIterator, typename Integer, typename T >
OutputIterator fill_n( OutputIterator result, Integer count, const T& value )
{
typedef typename primal_type<Integer>::primal_t primal_int;
for( primal_int i = 0; i < count; ++i,++result )
*result = value;
return result;
}
inline char* fill_n( char* result, def_size_t n, const char& value )
{
memset( result, value, n );
return ( result + n );
}
inline wchar_t* fill_n( wchar_t* result, def_size_t n, const wchar_t& value )
{
wmemset( result, value, n );
return ( result + n );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -