Reflection for RapidJSON 0.0.17
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
clangversionabstraction.h
Go to the documentation of this file.
1// this file is based on clangversionabstraction.h from https://github.com/woboq/moc-ng
2
3#ifndef REFLECTIVE_RAPIDJSON_CLANG_VERSION_ABSTRACTION_H
4#define REFLECTIVE_RAPIDJSON_CLANG_VERSION_ABSTRACTION_H
5
6#include <clang/Basic/SourceLocation.h>
7#include <clang/Basic/Version.h>
8
9#include <memory>
10
11namespace ReflectiveRapidJSON {
12
17template <typename T> struct MaybeUnique {
18 T *val;
19 operator T *()
20 {
21 return val;
22 }
23 template <typename X> operator std::unique_ptr<X>() &&
24 {
25 return std::unique_ptr<X>(val);
26 }
27};
28template <typename T> MaybeUnique<T> maybe_unique(T *val)
29{
30 return { val };
31}
32template <typename T> MaybeUnique<T> maybe_unique(std::unique_ptr<T> val)
33{
34 return { val.release() };
35}
36
41
42#if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR <= 5
43#define REFLECTIVE_RAPIDJSON_MAYBE_UNIQUE(t) t *
44#else
45#define REFLECTIVE_RAPIDJSON_MAYBE_UNIQUE(t) std::unique_ptr<t>
46#endif
47
51template <typename T> bool startsStrRefWith(T stringRef1, T stringRef2)
52{
53#if CLANG_VERSION_MAJOR >= 16
54 return stringRef1.starts_with(stringRef2);
55#else
56 return stringRef1.startswith(stringRef2);
57#endif
58}
59
60} // namespace ReflectiveRapidJSON
61
62#endif // REFLECTIVE_RAPIDJSON_CLANG_VERSION_ABSTRACTION_H
bool startsStrRefWith(T stringRef1, T stringRef2)
Tests whether an llvm::StringRef starts with another llvm::StringRef.
MaybeUnique< T > maybe_unique(T *val)
The MaybeUnique class represents either a std::unique_ptr or a raw pointer.