mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 17:56:02 +00:00
Add _a literal for named arguments
This commit is contained in:
@@ -18,23 +18,29 @@ template <typename T> struct arg_t;
|
||||
|
||||
/// Annotation for keyword arguments
|
||||
struct arg {
|
||||
arg(const char *name) : name(name) { }
|
||||
template <typename T> arg_t<T> operator=(const T &value);
|
||||
template <typename T, size_t N> arg_t<const T *> operator=(T const (&value)[N]);
|
||||
constexpr arg(const char *name) : name(name) { }
|
||||
|
||||
template <typename T>
|
||||
constexpr arg_t<T> operator=(const T &value) const { return {name, value}; }
|
||||
template <typename T, size_t N>
|
||||
constexpr arg_t<const T *> operator=(T const (&value)[N]) const {
|
||||
return operator=((const T *) value);
|
||||
};
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
/// Annotation for keyword arguments with default values
|
||||
template <typename T> struct arg_t : public arg {
|
||||
arg_t(const char *name, const T &value, const char *descr = nullptr)
|
||||
constexpr arg_t(const char *name, const T &value, const char *descr = nullptr)
|
||||
: arg(name), value(value), descr(descr) { }
|
||||
T value;
|
||||
const char *descr;
|
||||
};
|
||||
|
||||
template <typename T> arg_t<T> arg::operator=(const T &value) { return arg_t<T>(name, value); }
|
||||
template <typename T, size_t N> arg_t<const T *> arg::operator=(T const (&value)[N]) {
|
||||
return operator=((const T *) value);
|
||||
inline namespace literals {
|
||||
/// String literal version of arg
|
||||
constexpr arg operator"" _a(const char *name, size_t) { return {name}; }
|
||||
}
|
||||
|
||||
/// Annotation for methods
|
||||
|
||||
Reference in New Issue
Block a user