My Project
fill.hpp
Go to the documentation of this file.
1 
28 #ifndef BSL_FILL_HPP
29 #define BSL_FILL_HPP
30 
31 #include "cstdint.hpp"
32 #include "cstring.hpp"
33 #include "enable_if.hpp"
35 #include "is_fundamental.hpp"
36 #include "is_copy_assignable.hpp"
38 
39 namespace bsl
40 {
41  namespace details
42  {
53  template<typename VIEW, typename T>
54  constexpr void
55  fill_impl(VIEW &vw, T const &value) noexcept( // --
57  {
58  for (bsl::uintmax i{}; i < vw.size(); ++i) {
59  *vw.at_if(i) = value;
60  }
61  }
62  }
63 
78  template<typename VIEW, typename T>
79  constexpr enable_if_t<is_copy_assignable<T>::value>
80  fill(VIEW &vw, T const &value) noexcept( // --
82  {
84  if (T{} == value) {
85  bsl::builtin_memset(vw.data(), 0, vw.size_bytes());
86  }
87  else {
88  details::fill_impl(vw, value);
89  }
90  }
91  else {
92  details::fill_impl(vw, value);
93  }
94  }
95 
111  template<typename ITER, typename T>
112  constexpr enable_if_t<is_copy_assignable<T>::value>
113  fill(ITER first, ITER last, T const &value) noexcept( // --
115  {
116  for (; first < last; ++first) {
117  *first.get_if() = value;
118  }
119  }
120 }
121 
122 #endif
If the provided type is a fundamental type, provides the member constant value equal to true....
Definition: is_fundamental.hpp:76
constexpr enable_if_t< is_copy_assignable< T >::value > fill(VIEW &vw, T const &value) noexcept(//-- is_nothrow_copy_assignable< T >::value)
Sets all elements of a view to "value". T must be copy assignable.
Definition: fill.hpp:80
void * builtin_memset(void *const dst, bsl::int8 const ch, bsl::uintmax const count) noexcept
Same as std::memset with parameter checks. If dst is a nullptr, or count is 0, this function returns ...
Definition: cstring.hpp:79
constexpr void fill_impl(VIEW &vw, T const &value) noexcept(//-- is_nothrow_copy_assignable< T >::value)
Provides the internal implementation of the fill function. Specifically, this is the non-optimized ve...
Definition: fill.hpp:55
constexpr bool is_constant_evaluated() noexcept
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition: is_constant_evaluated.hpp:46
If the provided type is nothrow copy assignable, provides the member constant value equal to true....
Definition: is_nothrow_copy_assignable.hpp:49
::uintmax_t uintmax
defines a unsigned integer with the maximum possible size
Definition: cstdint.hpp:97