Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
make-clean.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Mateusz Malicki <m.malicki@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_UTILS_MAKE_CLEAN_HPP
26 #define COMMON_UTILS_MAKE_CLEAN_HPP
27 
28 #include <algorithm>
29 #include <type_traits>
30 
31 namespace utils {
32 
33 template<class T>
34 void make_clean(T& value)
35 {
36  static_assert(std::is_pod<T>::value, "make_clean require trivial and standard-layout");
37  std::fill_n(reinterpret_cast<char*>(&value), sizeof(value), 0);
38 }
39 
40 template<class T>
42 {
43  T value;
44  make_clean(value);
45  return value;
46 }
47 
48 } // namespace utils
49 
50 
51 #endif // COMMON_UTILS_MAKE_CLEAN_HPP
void make_clean(T &value)
Definition: make-clean.hpp:34