@@ -41,7 +41,8 @@ class Error : public std::exception {
41
41
explicit Error (const char * what) : err_(what) {}
42
42
43
43
template <typename ... Args>
44
- explicit Error (const char * format, const Args&... args) : err_(fmt::format(format, args...)) {}
44
+ explicit Error (std::string_view format, Args&&... args)
45
+ : err_(fmt::format(format, std::forward<Args>(args)...)) {}
45
46
46
47
virtual ~Error () noexcept = default ;
47
48
@@ -59,9 +60,10 @@ class ConfError : public Error {
59
60
60
61
ConfError (const Conf& c, const std::string& msg) : Error(msg), data_(c) {}
61
62
ConfError (const Conf& c, const char * msg) : Error(msg), data_(c) {}
63
+
62
64
template <typename ... Args>
63
- ConfError (const Conf& c, const char * format, const Args&... args)
64
- : Error(format, args...), data_(c) {}
65
+ ConfError (const Conf& c, std::string_view format, Args& &... args)
66
+ : Error(format, std::forward<Args>( args) ...), data_(c) {}
65
67
66
68
std::string file () const { return data_.file (); }
67
69
std::string root () const { return data_.root (); }
@@ -122,19 +124,49 @@ class SchemaError : public ConfError {
122
124
public: // Constructors
123
125
virtual ~SchemaError () noexcept = default ;
124
126
127
+ /* *
128
+ * Construct SchemaError with a ConfError.
129
+ *
130
+ * \param c ConfError
131
+ * \param s Schema used for validation
132
+ */
125
133
SchemaError (const ConfError& c, const Json& s) : ConfError(c), schema_(s) {}
126
134
135
+ /* *
136
+ * Construct SchemaError with a ConfError.
137
+ *
138
+ * \param c ConfError
139
+ * \param s Schema used for validation
140
+ * \param ctx Extra contextual data as JSON
141
+ */
127
142
SchemaError (const ConfError& c, const Json& s, const Json& ctx)
128
143
: ConfError(c), schema_(s), context_(ctx) {}
129
144
145
+ /* *
146
+ * Construct SchemaError.
147
+ *
148
+ * \param c Input Conf where error occurred
149
+ * \param s Schema used for validation
150
+ * \param format Message format string for fmt::format
151
+ * \param args Arguments to message format
152
+ */
130
153
template <typename ... Args>
131
- SchemaError (const Conf& c, const Json& s, const char * format, const Args&... args)
132
- : ConfError(c, format, args...), schema_(s) {}
133
-
154
+ SchemaError (const Conf& c, const Json& s, std::string_view format, Args&&... args)
155
+ : ConfError(c, format, std::forward<Args>(args)...), schema_(s) {}
156
+
157
+ /* *
158
+ * Construct SchemaError.
159
+ *
160
+ * \param c Input Conf where error occurred
161
+ * \param s Schema used for validation
162
+ * \param ctx Extra contextual data as JSON
163
+ * \param format Message format string for fmt::format
164
+ * \param args Arguments to message format
165
+ */
134
166
template <typename ... Args>
135
- SchemaError (const Conf& c, const Json& s, const Json& ctx, const char * format,
136
- const Args&... args)
137
- : ConfError(c, format, args...), schema_(s), context_(ctx) {}
167
+ SchemaError (const Conf& c, const Json& s, const Json& ctx, std::string_view format,
168
+ Args& &... args)
169
+ : ConfError(c, format, std::forward<Args>( args) ...), schema_(s), context_(ctx) {}
138
170
139
171
public: // Special
140
172
const Json& schema () const { return schema_; }
0 commit comments