Skip to content

Commit 9eca7d2

Browse files
committed
squash warnings from visual studio about wide character and narrowing. Makes sense to deal with byte streams anyway...
1 parent 2304e04 commit 9eca7d2

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

include/cpp-json/json.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ inline bool has_key(const object &o, const std::string &key);
6464
template <class In>
6565
inline value parse(In first, In last);
6666
inline value parse(std::istream &is);
67-
inline value parse(std::wistream &is);
6867
inline value parse(std::istream &&is);
69-
inline value parse(std::wistream &&is);
7068
inline value parse(const std::string &s);
71-
inline value parse(const std::wstring &s);
7269

7370
// convert a value to a JSON string
7471
enum {

include/cpp-json/json.tcc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,14 @@ inline value parse(std::istream &&is) {
129129
return parse(is);
130130
}
131131

132-
inline value parse(std::wistream &&is) {
133-
return parse(is);
134-
}
135-
136132
inline value parse(std::istream &is) {
137133
return parse((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>());
138134
}
139135

140-
inline value parse(std::wistream &is) {
141-
return parse((std::istreambuf_iterator<wchar_t>(is)), std::istreambuf_iterator<wchar_t>());
142-
}
143-
144136
inline value parse(const std::string &s) {
145137
return parse(s.begin(), s.end());
146138
}
147139

148-
inline value parse(const std::wstring &s) {
149-
return parse(s.begin(), s.end());
150-
}
151-
152140
inline bool is_string(const value &v) { return (v.type_ == value::type_string); }
153141
inline bool is_bool(const value &v) { return (v.type_ == value::type_boolean); }
154142
inline bool is_number(const value &v) { return (v.type_ == value::type_number); }

include/cpp-json/value.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ namespace json {
77
class array;
88
class object;
99

10+
namespace detail {
11+
template <class T>
12+
constexpr T static_max(T n) {
13+
return n;
14+
}
15+
16+
template <class T, class ... Args>
17+
constexpr T static_max(T n, Args ... args) {
18+
return n > static_max(args...) ? n : static_max(args...);
19+
}
20+
21+
template <class... Types>
22+
struct aligned_traits {
23+
static constexpr std::size_t alignment_value = static_max(alignof(Types)...);
24+
static constexpr std::size_t size_value = static_max(sizeof(Types)...);
25+
};
26+
}
27+
1028
class value {
1129
friend bool is_string(const value &v);
1230
friend bool is_bool(const value &v);
@@ -98,18 +116,12 @@ class value {
98116
// I would love to use std::aligned_union, but it doesn't seem widely supported
99117
// so instead, we kinda make our own, first we need a type which has the correct
100118
// size and alignment requirements based on the types we want to store
101-
union storage_union {
102-
invalid_t invalid;
103-
object_pointer object;
104-
array_pointer array;
105-
std::string string;
106-
};
107-
108-
// then we create a type which is generic, and has that same alignement and size
119+
using Tr = detail::aligned_traits<invalid_t, object_pointer, array_pointer, std::string>;
120+
109121
typedef struct {
110-
alignas(alignof(storage_union)) uint8_t data[sizeof(storage_union)];
122+
alignas(Tr::alignment_value) uint8_t data[Tr::size_value];
111123
} storage_type;
112-
124+
113125
storage_type value_;
114126
type type_;
115127
};

0 commit comments

Comments
 (0)