Skip to content

Commit 842da31

Browse files
committed
Replace deprecated std::iterator, std::is_pod, and std::aligned_storage
1 parent 6ad2144 commit 842da31

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

src.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(COMMONLIST
3939
${COMMON_DIR}/String.h
4040
${COMMON_DIR}/System.cpp
4141
${COMMON_DIR}/System.h
42+
${COMMON_DIR}/Type.h
4243
${COMMON_DIR}/Util.cpp
4344
${COMMON_DIR}/Util.h
4445
${COMMON_DIR}/cm/cm_load.cpp

src/common/FileSystem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,16 @@ namespace Path {
207207
} // namespace Path
208208

209209
// Iterator which iterates over all files in a directory
210-
template<typename State> class DirectoryIterator: public std::iterator<std::input_iterator_tag, std::string> {
210+
template<typename State> class DirectoryIterator {
211211
// State interface:
212212
// bool Advance(std::error_code& err);
213213
// std::string current;
214+
using iterator_category = std::input_iterator_tag;
215+
using value_type = std::string;
216+
using difference_type = void;
217+
using pointer = void;
218+
using reference = void;
219+
214220
public:
215221
DirectoryIterator()
216222
: state(nullptr) {}

src/common/Serialize.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4545
#include "Optional.h"
4646
#include "String.h"
4747

48+
#include "Type.h"
49+
4850
namespace Util {
4951

5052
/*
@@ -229,7 +231,7 @@ namespace Util {
229231
// This is only safe to use if every possible byte sequence represents a valid value for the
230232
// object. So it cannot be used for bool or a struct containing a bool.
231233
template<typename T>
232-
struct SerializeTraits<T, typename std::enable_if<std::is_pod<T>::value && !std::is_array<T>::value>::type> {
234+
struct SerializeTraits<T, typename std::enable_if<IsPod<T> && !std::is_array<T>::value>::type> {
233235
static void Write(Writer& stream, const T& value)
234236
{
235237
stream.WriteData(std::addressof(value), sizeof(value));
@@ -257,7 +259,7 @@ namespace Util {
257259

258260
// std::array for non-POD types (POD types are already handled by the base case)
259261
template<typename T, size_t N>
260-
struct SerializeTraits<std::array<T, N>, typename std::enable_if<!std::is_pod<T>::value>::type> {
262+
struct SerializeTraits<std::array<T, N>, typename std::enable_if<!IsPod<T>>::type> {
261263
static void Write(Writer& stream, const std::array<T, N>& value)
262264
{
263265
for (const T& x: value)
@@ -274,7 +276,7 @@ namespace Util {
274276

275277
// std::vector, with a specialization for POD types
276278
template<typename T>
277-
struct SerializeTraits<std::vector<T>, typename std::enable_if<std::is_pod<T>::value>::type> {
279+
struct SerializeTraits<std::vector<T>, typename std::enable_if<IsPod<T>>::type> {
278280
static void Write(Writer& stream, const std::vector<T>& value)
279281
{
280282
stream.WriteSize(value.size());
@@ -289,7 +291,7 @@ namespace Util {
289291
}
290292
};
291293
template<typename T>
292-
struct SerializeTraits<std::vector<T>, typename std::enable_if<!std::is_pod<T>::value>::type> {
294+
struct SerializeTraits<std::vector<T>, typename std::enable_if<!IsPod<T>>::type> {
293295
static void Write(Writer& stream, const std::vector<T>& value)
294296
{
295297
stream.WriteSize(value.size());

src/common/Type.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2013-2016, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#ifndef COMMON_TYPE_H_
32+
#define COMMON_TYPE_H_
33+
34+
#include <type_traits>
35+
36+
template<typename T>
37+
constexpr bool IsPod = std::is_standard_layout<T>::value && std::is_trivially_copyable<T>::value && std::is_trivially_default_constructible<T>::value;
38+
39+
#endif // COMMON_TYPE_H_

src/common/Util.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ template<typename T> class uninitialized {
151151
uninitialized& operator=(const uninitialized&) = delete;
152152
uninitialized& operator=(uninitialized&&) = delete;
153153

154+
alignas( T ) uint8_t data[sizeof( T )];
155+
154156
template<typename... Args> void construct(Args&&... args)
155157
{
156158
new(&data) T(std::forward<Args>(args)...);
@@ -171,9 +173,6 @@ template<typename T> class uninitialized {
171173
{
172174
return *reinterpret_cast<const T*>(&data);
173175
}
174-
175-
private:
176-
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type data;
177176
};
178177

179178
// std::make_unique is not available until C++14.

0 commit comments

Comments
 (0)