{
namespace test
{
-util::optional<std::vector<spirv::word>> load_file(const char *fileName)
+util::optional<std::vector<spirv::Word>> load_file(const char *fileName)
{
- using spirv::word;
+ using spirv::Word;
constexpr int eof = std::char_traits<char>::eof();
std::ifstream is;
is.open(fileName, std::ios::in | std::ios::binary);
if(!is)
return {};
constexpr std::size_t block_size = 0x1000;
- std::vector<std::array<word, block_size>> blocks;
- std::array<unsigned char, sizeof(word)> word_bytes{};
- static_assert(sizeof(word) == 4, "");
+ std::vector<std::array<Word, block_size>> blocks;
+ std::array<unsigned char, sizeof(Word)> word_bytes{};
+ static_assert(sizeof(Word) == 4, "");
static_assert(std::is_same<std::uint8_t, unsigned char>::value, "");
- auto read_little_endian = [](const unsigned char *bytes) -> word
+ auto read_little_endian = [](const unsigned char *bytes) -> Word
{
- word retval = bytes[3];
+ Word retval = bytes[3];
retval <<= 8;
retval |= bytes[2];
retval <<= 8;
retval |= bytes[0];
return retval;
};
- auto read_big_endian = [](const unsigned char *bytes) -> word
+ auto read_big_endian = [](const unsigned char *bytes) -> Word
{
- word retval = bytes[0];
+ Word retval = bytes[0];
retval <<= 8;
retval |= bytes[1];
retval <<= 8;
return {};
byte = v;
}
- word (*read_word_fn)(const unsigned char *) = nullptr;
+ Word (*read_word_fn)(const unsigned char *) = nullptr;
if(read_little_endian(word_bytes.data()) == spirv::magic_number)
read_word_fn = read_little_endian;
else if(read_big_endian(word_bytes.data()) == spirv::magic_number)
blocks.emplace_back();
}
}
- std::vector<word> retval;
+ std::vector<Word> retval;
retval.reserve(word_count);
word_in_block_index = 0;
for(std::size_t word_index = 0, block_index = 0; word_index < word_count; word_index++)
return std::move(retval);
}
-void dump_words(const spirv::word *words, std::size_t word_count)
+void dump_words(const spirv::Word *words, std::size_t word_count)
{
constexpr std::size_t max_words_per_line = 4;
auto old_fill = std::cout.fill('0');
std::string chars = "";
auto write_line_ending = [&]()
{
- while(current_words_per_line < max_words_per_line)
- {
+ while(current_words_per_line < max_words_per_line)
+ {
std::cout << seperator;
seperator = " ";
std::cout.width(8);
std::cout << "";
std::cout.fill('0');
current_words_per_line++;
- }
- std::cout << seperator << " |" << chars << "|\n";
+ }
+ std::cout << seperator << " |" << chars << "|\n";
seperator = "";
wrote_line_ending = true;
wrote_line_beginning = false;
};
auto append_char = [&](unsigned ch)
{
- if(ch >= 0x20U && ch < 0x7FU)
- chars += static_cast<char>(ch);
- else
- chars += '.';
+ if(ch >= 0x20U && ch < 0x7FU)
+ chars += static_cast<char>(ch);
+ else
+ chars += '.';
};
- auto write_word = [&](spirv::word w)
+ auto write_word = [&](spirv::Word w)
{
std::cout << seperator;
seperator = " ";
std::cout.flags(old_flags);
}
-void dump_words(const std::vector<spirv::word> &words)
+void dump_words(const std::vector<spirv::Word> &words)
{
dump_words(words.data(), words.size());
}
{
namespace ast
{
-struct copyright
+struct Copyright
{
- json::ast::array value;
- copyright() : value()
+ json::ast::Array value;
+ Copyright() : value()
{
}
- explicit copyright(json::ast::array value) noexcept : value(std::move(value))
+ explicit Copyright(json::ast::Array value) noexcept : value(std::move(value))
{
}
};
-struct instructions
+struct Instructions
{
#warning finish
};
-struct operand_kinds
+struct Operand_kinds
{
#warning finish
};
-struct top_level
+struct Top_level
{
- copyright copyright;
+ Copyright copyright;
std::uint32_t magic_number;
std::size_t major_version;
std::size_t minor_version;
std::size_t revision;
- instructions instructions;
- operand_kinds operand_kinds;
- top_level(ast::copyright copyright,
+ Instructions instructions;
+ Operand_kinds operand_kinds;
+ Top_level(Copyright copyright,
std::uint32_t magic_number,
std::size_t major_version,
std::size_t minor_version,
std::size_t revision,
- ast::instructions instructions,
- ast::operand_kinds operand_kinds)
+ Instructions instructions,
+ Operand_kinds operand_kinds)
: copyright(std::move(copyright)),
magic_number(magic_number),
major_version(major_version),
}
try
{
- auto source = file_name == "-" ? json::source::load_stdin() :
- json::source::load_file(std::move(file_name));
+ auto source = file_name == "-" ? json::Source::load_stdin() :
+ json::Source::load_file(std::move(file_name));
try
{
auto ast = parser::parse(json::parse(&source));
}
- catch(json::parse_error &e)
+ catch(json::Parse_error &e)
{
std::cerr << "error: " << e.what() << std::endl;
return 1;
}
- catch(parser::parse_error &e)
+ catch(parser::Parse_error &e)
{
std::cerr << "error: " << e.what() << std::endl;
return 1;
{
namespace parser
{
-std::string path::to_string() const
+std::string Path::to_string() const
{
std::ostringstream ss;
ss << "root";
}
else
{
- json::ast::string_value::write(ss, util::get<std::string>(e));
+ json::ast::String_value::write(ss, util::get<std::string>(e));
}
ss << ']';
}
{
template <typename Value, std::size_t N>
Value get_value_or_throw_parse_error(util::optional<Value> value,
- path_builder_base *path_builder,
+ Path_builder_base *path_builder,
const char(&message)[N])
{
if(value)
return std::move(*value);
- throw parse_error(path_builder ? path_builder->path() : path{}, message);
+ throw Parse_error(path_builder ? path_builder->path() : Path{}, message);
}
-ast::copyright parse_copyright(json::ast::value value, const path_builder_base *parent_path_builder)
+ast::Copyright parse_copyright(json::ast::Value value, const Path_builder_base *parent_path_builder)
{
- if(json::ast::get_value_kind(value) != json::ast::value_kind::array)
- throw parse_error(parent_path_builder->path(), "copyright is not an array");
+ if(json::ast::get_value_kind(value) != json::ast::Value_kind::array)
+ throw Parse_error(parent_path_builder->path(), "copyright is not an array");
auto ©right_array =
- static_cast<json::ast::array &>(*util::get<json::ast::composite_value_pointer>(value));
+ static_cast<json::ast::Array &>(*util::get<json::ast::Composite_value_pointer>(value));
for(std::size_t index = 0; index < copyright_array.values.size(); index++)
{
- path_builder<std::size_t> path_builder(&index, parent_path_builder);
+ Path_builder<std::size_t> path_builder(&index, parent_path_builder);
auto &element = copyright_array.values[index];
- if(json::ast::get_value_kind(element) != json::ast::value_kind::string)
- throw parse_error(parent_path_builder->path(),
+ if(json::ast::get_value_kind(element) != json::ast::Value_kind::string)
+ throw Parse_error(parent_path_builder->path(),
"copyright array's element is not a string");
}
- return ast::copyright(std::move(copyright_array));
+ return ast::Copyright(std::move(copyright_array));
}
-ast::operand_kinds parse_operand_kinds(json::ast::value value,
- const path_builder_base *parent_path_builder)
+ast::Operand_kinds parse_operand_kinds(json::ast::Value value,
+ const Path_builder_base *parent_path_builder)
{
- if(json::ast::get_value_kind(value) != json::ast::value_kind::array)
- throw parse_error(parent_path_builder->path(), "operand_kinds is not an array");
+ if(json::ast::get_value_kind(value) != json::ast::Value_kind::array)
+ throw Parse_error(parent_path_builder->path(), "operand_kinds is not an array");
auto &operand_kinds_array =
- static_cast<json::ast::array &>(*util::get<json::ast::composite_value_pointer>(value));
+ static_cast<json::ast::Array &>(*util::get<json::ast::Composite_value_pointer>(value));
static_cast<void>(operand_kinds_array);
#warning finish
- return ast::operand_kinds();
+ return ast::Operand_kinds();
}
-ast::instructions parse_instructions(json::ast::value value,
- const path_builder_base *parent_path_builder)
+ast::Instructions parse_instructions(json::ast::Value value,
+ const Path_builder_base *parent_path_builder)
{
- if(json::ast::get_value_kind(value) != json::ast::value_kind::array)
- throw parse_error(parent_path_builder->path(), "instructions is not an array");
+ if(json::ast::get_value_kind(value) != json::ast::Value_kind::array)
+ throw Parse_error(parent_path_builder->path(), "instructions is not an array");
auto &instructions_array =
- static_cast<json::ast::array &>(*util::get<json::ast::composite_value_pointer>(value));
+ static_cast<json::ast::Array &>(*util::get<json::ast::Composite_value_pointer>(value));
static_cast<void>(instructions_array);
#warning finish
- return ast::instructions();
+ return ast::Instructions();
}
template <typename T>
-T parse_integer(const json::ast::value &value,
- const path_builder_base *parent_path_builder,
+T parse_integer(const json::ast::Value &value,
+ const Path_builder_base *parent_path_builder,
const char *name)
{
- if(json::ast::get_value_kind(value) != json::ast::value_kind::number)
- throw parse_error(parent_path_builder->path(), std::string(name) + " is not a number");
- auto number_value = util::get<json::ast::number_value>(value);
+ if(json::ast::get_value_kind(value) != json::ast::Value_kind::number)
+ throw Parse_error(parent_path_builder->path(), std::string(name) + " is not a number");
+ auto number_value = util::get<json::ast::Number_value>(value);
T retval = number_value.value;
if(retval != number_value.value) // not an exact value
- throw parse_error(parent_path_builder->path(), std::string(name) + " is not an integer");
+ throw Parse_error(parent_path_builder->path(), std::string(name) + " is not an integer");
return retval;
}
}
template <typename T>
-T parse_hex_integer_string(const json::ast::value &value,
- const path_builder_base *parent_path_builder,
+T parse_hex_integer_string(const json::ast::Value &value,
+ const Path_builder_base *parent_path_builder,
const char *name,
std::size_t min_length,
std::size_t max_length)
{
- if(json::ast::get_value_kind(value) != json::ast::value_kind::string)
- throw parse_error(parent_path_builder->path(), std::string(name) + " is not a string");
- auto &string_value = util::get<json::ast::string_value>(value);
+ if(json::ast::get_value_kind(value) != json::ast::Value_kind::string)
+ throw Parse_error(parent_path_builder->path(), std::string(name) + " is not a string");
+ auto &string_value = util::get<json::ast::String_value>(value);
constexpr std::size_t hex_number_prefix_length = 2; // std::strlen("0x")
if(string_value.value.size() < hex_number_prefix_length || string_value.value[0] != '0'
|| (string_value.value[1] != 'x' && string_value.value[1] != 'X'))
- throw parse_error(parent_path_builder->path(),
+ throw Parse_error(parent_path_builder->path(),
std::string(name) + " is not a valid hex number in a string");
constexpr T max_value = std::numeric_limits<T>::max();
constexpr unsigned base = 0x10;
char ch = string_value.value[i];
int digit = get_digit_value(ch, base);
if(digit < 0)
- throw parse_error(parent_path_builder->path(),
+ throw Parse_error(parent_path_builder->path(),
std::string(name) + ": not a valid hex digit");
if(digit_count > max_length)
- throw parse_error(parent_path_builder->path(),
+ throw Parse_error(parent_path_builder->path(),
std::string(name) + " has too many digits");
if(retval > max_value / base
|| (retval = max_value / base && static_cast<unsigned>(digit) > max_value % base))
- throw parse_error(parent_path_builder->path(), std::string(name) + ": value too big");
+ throw Parse_error(parent_path_builder->path(), std::string(name) + ": value too big");
retval *= base;
retval += digit;
}
if(digit_count < min_length)
- throw parse_error(parent_path_builder->path(),
+ throw Parse_error(parent_path_builder->path(),
std::string(name) + " doesn't have enough digits");
return retval;
}
}
-ast::top_level parse(json::ast::value &&top_level_value)
+ast::Top_level parse(json::ast::Value &&top_level_value)
{
- if(json::ast::get_value_kind(top_level_value) != json::ast::value_kind::object)
- throw parse_error({}, "top level value is not an object");
- auto &top_level_object = static_cast<const json::ast::object &>(
- *util::get<json::ast::composite_value_pointer>(top_level_value));
- util::optional<ast::copyright> copyright;
+ if(json::ast::get_value_kind(top_level_value) != json::ast::Value_kind::object)
+ throw Parse_error({}, "top level value is not an object");
+ auto &top_level_object = static_cast<const json::ast::Object &>(
+ *util::get<json::ast::Composite_value_pointer>(top_level_value));
+ util::optional<ast::Copyright> copyright;
util::optional<std::uint32_t> magic_number;
util::optional<std::size_t> major_version;
util::optional<std::size_t> minor_version;
util::optional<std::size_t> revision;
- util::optional<ast::instructions> instructions;
- util::optional<ast::operand_kinds> operand_kinds;
+ util::optional<ast::Instructions> instructions;
+ util::optional<ast::Operand_kinds> operand_kinds;
for(auto &entry : top_level_object.values)
{
const auto &key = std::get<0>(entry);
auto &entry_value = std::get<1>(entry);
- path_builder<std::string> path_builder(&key, nullptr);
+ Path_builder<std::string> path_builder(&key, nullptr);
if(key == "copyright")
{
copyright = parse_copyright(std::move(entry_value), &path_builder);
}
else
{
- throw parse_error(path_builder.path(), "unknown key");
+ throw Parse_error(path_builder.path(), "unknown key");
}
}
- auto retval = ast::top_level(
+ auto retval = ast::Top_level(
get_value_or_throw_parse_error(std::move(copyright), nullptr, "missing copyright"),
get_value_or_throw_parse_error(magic_number, nullptr, "missing magic_number"),
get_value_or_throw_parse_error(major_version, nullptr, "missing major_version"),
get_value_or_throw_parse_error(revision, nullptr, "missing revision"),
get_value_or_throw_parse_error(instructions, nullptr, "missing instructions"),
get_value_or_throw_parse_error(operand_kinds, nullptr, "missing operand_kinds"));
- throw parse_error({}, "not finished implementing");
+ throw Parse_error({}, "not finished implementing");
}
}
}
{
namespace parser
{
-struct path
+struct Path
{
typedef util::variant<std::size_t, std::string> element;
std::vector<element> elements;
- path() : elements()
+ Path() : elements()
{
}
- path(std::vector<element> elements) : elements(std::move(elements))
+ Path(std::vector<element> elements) : elements(std::move(elements))
{
}
- path(std::initializer_list<element> elements) : elements(elements)
+ Path(std::initializer_list<element> elements) : elements(elements)
{
}
std::string to_string() const;
};
-struct path_builder_base
+struct Path_builder_base
{
- path_builder_base(const path_builder_base &) = delete;
- path_builder_base &operator=(const path_builder_base &) = delete;
- virtual ~path_builder_base() = default;
- const path_builder_base *const parent;
+ Path_builder_base(const Path_builder_base &) = delete;
+ Path_builder_base &operator=(const Path_builder_base &) = delete;
+ virtual ~Path_builder_base() = default;
+ const Path_builder_base *const parent;
const std::size_t element_count;
- explicit path_builder_base(const path_builder_base *parent) noexcept
+ explicit Path_builder_base(const Path_builder_base *parent) noexcept
: parent(parent),
element_count(parent ? parent->element_count + 1 : 1)
{
}
- virtual path::element get_element() const = 0;
- path path() const
+ virtual Path::element get_element() const = 0;
+ Path path() const
{
- std::vector<path::element> elements;
+ std::vector<Path::element> elements;
elements.resize(element_count);
- const path_builder_base *node = this;
+ const Path_builder_base *node = this;
for(std::size_t i = 0, j = element_count - 1; i < element_count;
i++, j--, node = node->parent)
{
};
template <typename T>
-struct path_builder final : public path_builder_base
+struct Path_builder final : public Path_builder_base
{
const T *value;
- path_builder(const T *value, const path_builder_base *parent) noexcept
- : path_builder_base(parent),
+ Path_builder(const T *value, const Path_builder_base *parent) noexcept
+ : Path_builder_base(parent),
value(value)
{
}
- virtual path::element get_element() const override
+ virtual Path::element get_element() const override
{
return *value;
}
};
-class parse_error : public std::runtime_error
+class Parse_error : public std::runtime_error
{
public:
- path path;
- parse_error(parser::path path, const std::string &message)
+ Path path;
+ Parse_error(parser::Path path, const std::string &message)
: runtime_error("at " + path.to_string() + ": " + message), path(std::move(path))
{
}
};
-ast::top_level parse(json::ast::value &&top_level_value);
+ast::Top_level parse(json::ast::Value &&top_level_value);
}
}
}
{
namespace json
{
-void write_state::write_indent(std::ostream &os) const
+void Write_state::write_indent(std::ostream &os) const
{
for(std::size_t i = indent_level; i > 0; i--)
os << options.indent_text;
{
namespace soft_float = util::soft_float;
-void null_value::write(std::ostream &os, write_state &state) const
+void Null_value::write(std::ostream &os, Write_state &state) const
{
os << "null";
}
-void boolean_value::write(std::ostream &os, write_state &state) const
+void Boolean_value::write(std::ostream &os, Write_state &state) const
{
os << (value ? "true" : "false");
}
}
}
-void string_value::write(std::ostream &os, const std::string &value, write_state &state)
+void String_value::write(std::ostream &os, const std::string &value, Write_state &state)
{
os << '\"';
for(unsigned char ch : value)
std::uint64_t value,
unsigned base) noexcept(noexcept(write_char('0')))
{
- assert(base >= number_value::min_base && base <= number_value::max_base);
+ assert(base >= Number_value::min_base && base <= Number_value::max_base);
char buffer[max_integer_buffer_size]{};
std::size_t buffer_used = 0;
do
// code modified from
// https://github.com/programmerjake/javascript-tasklets/blob/master/javascript_tasklets/value.cpp
// based on the ECMAScript ToString algorithm for numbers
- assert(base >= number_value::min_base && base <= number_value::max_base);
+ assert(base >= Number_value::min_base && base <= Number_value::max_base);
const char exponent_char = base == 10 ? 'e' : base == 16 ? 'h' : base == 8 ? 'o' : 'E';
soft_float::ExtendedFloat value(valueIn), base_f(static_cast<std::uint64_t>(base));
auto inv_base_f = soft_float::ExtendedFloat::One() / base_f;
}
}
-std::string number_value::append_double_to_string(double value, std::string buffer, unsigned base)
+std::string Number_value::append_double_to_string(double value, std::string buffer, unsigned base)
{
write_number(
[&](char ch)
return buffer;
}
-std::size_t number_value::double_to_buffer(double value,
+std::size_t Number_value::double_to_buffer(double value,
char *output_buffer,
std::size_t output_buffer_size,
bool require_null_terminator,
return used_buffer_size; // report used buffer excluding the null terminator
}
-std::string number_value::append_unsigned_integer_to_string(std::uint64_t value,
+std::string Number_value::append_unsigned_integer_to_string(std::uint64_t value,
std::string buffer,
unsigned base)
{
return buffer;
}
-std::size_t number_value::unsigned_integer_to_buffer(std::uint64_t value,
+std::size_t Number_value::unsigned_integer_to_buffer(std::uint64_t value,
char *output_buffer,
std::size_t output_buffer_size,
bool require_null_terminator,
return used_buffer_size; // report used buffer excluding the null terminator
}
-std::string number_value::append_signed_integer_to_string(std::int64_t value,
+std::string Number_value::append_signed_integer_to_string(std::int64_t value,
std::string buffer,
unsigned base)
{
return buffer;
}
-std::size_t number_value::signed_integer_to_buffer(std::int64_t value,
+std::size_t Number_value::signed_integer_to_buffer(std::int64_t value,
char *output_buffer,
std::size_t output_buffer_size,
bool require_null_terminator,
return used_buffer_size; // report used buffer excluding the null terminator
}
-void number_value::write(std::ostream &os, write_state &state, unsigned base) const
+void Number_value::write(std::ostream &os, Write_state &state, unsigned base) const
{
write_number(
[&](char ch)
base);
}
-void object::write(std::ostream &os, write_state &state) const
+void Object::write(std::ostream &os, Write_state &state) const
{
os << '{';
if(!values.empty())
{
- write_state::push_indent push_indent(state);
+ Write_state::Push_indent push_indent(state);
auto seperator = "";
- auto write_entry = [&](const std::pair<std::string, value> &entry)
+ auto write_entry = [&](const std::pair<std::string, Value> &entry)
{
const std::string &key = std::get<0>(entry);
- const value &value = std::get<1>(entry);
+ const Value &value = std::get<1>(entry);
os << seperator;
seperator = ",";
if(state.options.composite_value_elements_on_seperate_lines)
os << '\n';
state.write_indent(os);
}
- string_value::write(os, key, state);
+ String_value::write(os, key, state);
os << ':';
json::write(os, value, state);
};
os << '}';
}
-void array::write(std::ostream &os, write_state &state) const
+void Array::write(std::ostream &os, Write_state &state) const
{
os << '[';
if(!values.empty())
{
- write_state::push_indent push_indent(state);
+ Write_state::Push_indent push_indent(state);
auto seperator = "";
- for(const value &v : values)
+ for(const Value &v : values)
{
os << seperator;
seperator = ",";
{
namespace json
{
-struct write_options
+struct Write_options
{
bool composite_value_elements_on_seperate_lines = false;
bool sort_object_values = false;
std::string indent_text = "";
- write_options()
+ Write_options()
{
}
- write_options(bool composite_value_elements_on_seperate_lines,
+ Write_options(bool composite_value_elements_on_seperate_lines,
bool sort_object_values,
std::string indent_text) noexcept
: composite_value_elements_on_seperate_lines(composite_value_elements_on_seperate_lines),
indent_text(std::move(indent_text))
{
}
- static write_options defaults()
+ static Write_options defaults()
{
return {};
}
- static write_options pretty(std::string indent_text = " ")
+ static Write_options pretty(std::string indent_text = " ")
{
- return write_options(true, true, std::move(indent_text));
+ return Write_options(true, true, std::move(indent_text));
}
};
-struct write_state
+struct Write_state
{
- write_options options;
+ Write_options options;
std::size_t indent_level = 0;
- class push_indent final
+ class Push_indent final
{
- push_indent(const push_indent &) = delete;
- push_indent &operator=(const push_indent &) = delete;
+ Push_indent(const Push_indent &) = delete;
+ Push_indent &operator=(const Push_indent &) = delete;
private:
- write_state &state;
+ Write_state &state;
bool finished = false;
public:
- push_indent(write_state &state) : state(state)
+ Push_indent(Write_state &state) : state(state)
{
state.indent_level++;
}
state.indent_level--;
finished = true;
}
- ~push_indent()
+ ~Push_indent()
{
if(!finished)
state.indent_level--;
}
};
- write_state(write_options options) : options(std::move(options))
+ Write_state(Write_options options) : options(std::move(options))
{
}
void write_indent(std::ostream &os) const;
namespace ast
{
-enum class value_kind
+enum class Value_kind
{
null,
boolean,
array
};
-struct null_value final
+struct Null_value final
{
- constexpr null_value() noexcept = default;
- constexpr null_value(std::nullptr_t) noexcept
+ constexpr Null_value() noexcept = default;
+ constexpr Null_value(std::nullptr_t) noexcept
{
}
- void write(std::ostream &os, write_state &state) const;
- null_value duplicate() const noexcept
+ void write(std::ostream &os, Write_state &state) const;
+ Null_value duplicate() const noexcept
{
return {};
}
- const null_value *operator->() const noexcept
+ const Null_value *operator->() const noexcept
{
return this;
}
- const null_value &operator*() const noexcept
+ const Null_value &operator*() const noexcept
{
return *this;
}
- constexpr value_kind get_value_kind() const noexcept
+ constexpr Value_kind get_value_kind() const noexcept
{
- return value_kind::null;
+ return Value_kind::null;
}
};
-struct boolean_value final
+struct Boolean_value final
{
bool value;
template <typename T, typename = typename std::enable_if<std::is_same<T, bool>::value>::type>
- constexpr boolean_value(T value) noexcept : value(value)
+ constexpr Boolean_value(T value) noexcept : value(value)
{
}
- void write(std::ostream &os, write_state &state) const;
- boolean_value duplicate() const noexcept
+ void write(std::ostream &os, Write_state &state) const;
+ Boolean_value duplicate() const noexcept
{
return *this;
}
- const boolean_value *operator->() const noexcept
+ const Boolean_value *operator->() const noexcept
{
return this;
}
- const boolean_value &operator*() const noexcept
+ const Boolean_value &operator*() const noexcept
{
return *this;
}
- constexpr value_kind get_value_kind() const noexcept
+ constexpr Value_kind get_value_kind() const noexcept
{
- return value_kind::boolean;
+ return Value_kind::boolean;
}
};
-struct string_value final
+struct String_value final
{
std::string value;
template <
typename T,
typename = typename std::enable_if<!std::is_same<T, std::nullptr_t>::value
&& std::is_convertible<T, std::string>::value>::type>
- string_value(T value) noexcept : value(std::move(value))
+ String_value(T value) noexcept : value(std::move(value))
{
}
- static void write(std::ostream &os, const std::string &value, write_state &state);
+ static void write(std::ostream &os, const std::string &value, Write_state &state);
static void write(std::ostream &os, const std::string &value)
{
- write_state state(write_options::defaults());
+ Write_state state(Write_options::defaults());
write(os, value, state);
}
- void write(std::ostream &os, write_state &state) const
+ void write(std::ostream &os, Write_state &state) const
{
write(os, value, state);
}
- string_value duplicate() const noexcept
+ String_value duplicate() const noexcept
{
return *this;
}
- const string_value *operator->() const noexcept
+ const String_value *operator->() const noexcept
{
return this;
}
- const string_value &operator*() const noexcept
+ const String_value &operator*() const noexcept
{
return *this;
}
- constexpr value_kind get_value_kind() const noexcept
+ constexpr Value_kind get_value_kind() const noexcept
{
- return value_kind::string;
+ return Value_kind::string;
}
};
-struct number_value final
+struct Number_value final
{
double value;
static_assert(std::numeric_limits<double>::is_iec559 && std::numeric_limits<double>::radix == 2,
template <typename T,
typename = typename std::enable_if<std::is_arithmetic<T>::value
&& !std::is_same<T, bool>::value>::type>
- number_value(T value) noexcept : value(value)
+ Number_value(T value) noexcept : value(value)
{
}
explicit operator std::string() const
std::size_t output_buffer_size,
bool require_null_terminator = true,
unsigned base = default_base) noexcept;
- void write(std::ostream &os, write_state &state, unsigned base = default_base) const;
- number_value duplicate() const noexcept
+ void write(std::ostream &os, Write_state &state, unsigned base = default_base) const;
+ Number_value duplicate() const noexcept
{
return *this;
}
- const number_value *operator->() const noexcept
+ const Number_value *operator->() const noexcept
{
return this;
}
- const number_value &operator*() const noexcept
+ const Number_value &operator*() const noexcept
{
return *this;
}
- constexpr value_kind get_value_kind() const noexcept
+ constexpr Value_kind get_value_kind() const noexcept
{
- return value_kind::number;
+ return Value_kind::number;
}
};
-struct composite_value;
+struct Composite_value;
-class composite_value_pointer
+class Composite_value_pointer
{
private:
- std::shared_ptr<composite_value> value;
+ std::shared_ptr<Composite_value> value;
public:
- constexpr composite_value_pointer() noexcept = default;
+ constexpr Composite_value_pointer() noexcept = default;
template <typename T,
- typename = typename std::enable_if<std::is_base_of<composite_value, T>::value>::type>
- composite_value_pointer(std::shared_ptr<T> value) noexcept : value(std::move(value))
+ typename = typename std::enable_if<std::is_base_of<Composite_value, T>::value>::type>
+ Composite_value_pointer(std::shared_ptr<T> value) noexcept : value(std::move(value))
{
}
- composite_value *operator->() const noexcept
+ Composite_value *operator->() const noexcept
{
return value.operator->();
}
- composite_value &operator*() const noexcept
+ Composite_value &operator*() const noexcept
{
return *value;
}
- const std::shared_ptr<composite_value> &get() const &noexcept
+ const std::shared_ptr<Composite_value> &get() const &noexcept
{
return value;
}
- std::shared_ptr<composite_value> get() && noexcept
+ std::shared_ptr<Composite_value> get() && noexcept
{
- std::shared_ptr<composite_value> retval = nullptr;
+ std::shared_ptr<Composite_value> retval = nullptr;
retval.swap(value);
return retval;
}
};
typedef util::
- variant<null_value, boolean_value, string_value, number_value, composite_value_pointer> value;
+ variant<Null_value, Boolean_value, String_value, Number_value, Composite_value_pointer> Value;
-struct composite_value
+struct Composite_value
{
- composite_value() = default;
- virtual ~composite_value() = default;
- virtual void write(std::ostream &os, write_state &state) const = 0;
- virtual composite_value_pointer duplicate() const = 0;
- operator value() const
+ Composite_value() = default;
+ virtual ~Composite_value() = default;
+ virtual void write(std::ostream &os, Write_state &state) const = 0;
+ virtual Composite_value_pointer duplicate() const = 0;
+ operator Value() const
{
return duplicate();
}
- virtual value_kind get_value_kind() const noexcept = 0;
+ virtual Value_kind get_value_kind() const noexcept = 0;
};
-inline value duplicate(const value &v)
+inline Value duplicate(const Value &v)
{
return util::visit(
- [](const auto &v) -> value
+ [](const auto &v) -> Value
{
return v->duplicate();
},
v);
}
-struct object final : public composite_value
+struct Object final : public Composite_value
{
- std::unordered_map<std::string, value> values;
- object() : values()
+ std::unordered_map<std::string, Value> values;
+ Object() : values()
{
}
- object(std::unordered_map<std::string, value> values) noexcept : values(std::move(values))
+ Object(std::unordered_map<std::string, Value> values) noexcept : values(std::move(values))
{
}
- virtual void write(std::ostream &os, write_state &state) const override;
- virtual composite_value_pointer duplicate() const override
+ virtual void write(std::ostream &os, Write_state &state) const override;
+ virtual Composite_value_pointer duplicate() const override
{
- std::unordered_map<std::string, value> new_values;
+ std::unordered_map<std::string, Value> new_values;
for(auto &entry : values)
{
new_values.emplace(std::get<0>(entry), ast::duplicate(std::get<1>(entry)));
}
- return std::make_shared<object>(std::move(new_values));
+ return std::make_shared<Object>(std::move(new_values));
}
- value_kind get_value_kind() const noexcept override
+ Value_kind get_value_kind() const noexcept override
{
- return value_kind::object;
+ return Value_kind::object;
}
};
-struct array final : public composite_value
+struct Array final : public Composite_value
{
- std::vector<value> values;
- array() : values()
+ std::vector<Value> values;
+ Array() : values()
{
}
- array(std::vector<value> values) noexcept : values(std::move(values))
+ Array(std::vector<Value> values) noexcept : values(std::move(values))
{
}
- virtual void write(std::ostream &os, write_state &state) const override;
- virtual composite_value_pointer duplicate() const override
+ virtual void write(std::ostream &os, Write_state &state) const override;
+ virtual Composite_value_pointer duplicate() const override
{
- std::vector<value> new_values;
+ std::vector<Value> new_values;
new_values.reserve(values.size());
for(auto &value : values)
new_values.emplace_back(ast::duplicate(value));
- return std::make_shared<array>(std::move(new_values));
+ return std::make_shared<Array>(std::move(new_values));
}
- value_kind get_value_kind() const noexcept override
+ Value_kind get_value_kind() const noexcept override
{
- return value_kind::array;
+ return Value_kind::array;
}
};
-inline value_kind get_value_kind(const value &v) noexcept
+inline Value_kind get_value_kind(const Value &v) noexcept
{
return util::visit(
- [&](const auto &v) -> value_kind
+ [&](const auto &v) -> Value_kind
{
return v->get_value_kind();
},
}
}
-inline void write(std::ostream &os, const ast::value &v, write_state &state)
+inline void write(std::ostream &os, const ast::Value &v, Write_state &state)
{
util::visit(
[&](const auto &v) -> void
v);
}
-inline void write(std::ostream &os, const ast::value &v, write_options options = {})
+inline void write(std::ostream &os, const ast::Value &v, Write_options options = {})
{
- write_state state(std::move(options));
+ Write_state state(std::move(options));
write(os, v, state);
}
}
}
}
-std::vector<std::size_t> source::find_line_start_indexes(const char *contents,
+std::vector<std::size_t> Source::find_line_start_indexes(const char *contents,
std::size_t contents_size)
{
std::size_t retval_size = 0;
return retval;
}
-source source::load_file(std::string file_name)
+Source Source::load_file(std::string file_name)
{
// TODO: add code to use mmap
std::ifstream is;
std::size_t contents_size = buffer.size();
auto buffer_ptr = std::make_shared<std::vector<char>>(std::move(buffer));
std::shared_ptr<const char> contents(buffer_ptr, buffer_ptr->data());
- return source(std::move(file_name), std::move(contents), contents_size);
+ return Source(std::move(file_name), std::move(contents), contents_size);
}
-source source::load_stdin()
+Source Source::load_stdin()
{
auto &is = std::cin;
is.clear();
std::size_t contents_size = buffer.size();
auto buffer_ptr = std::make_shared<std::vector<char>>(std::move(buffer));
std::shared_ptr<const char> contents(buffer_ptr, buffer_ptr->data());
- return source("stdin", std::move(contents), contents_size);
+ return Source("stdin", std::move(contents), contents_size);
}
-std::ostream &operator<<(std::ostream &os, const source::line_and_column &v)
+std::ostream &operator<<(std::ostream &os, const Source::Line_and_column &v)
{
os << v.to_string();
return os;
}
-source::line_and_index source::get_line_and_start_index(std::size_t char_index) const noexcept
+Source::Line_and_index Source::get_line_and_start_index(std::size_t char_index) const noexcept
{
std::size_t line =
1 + line_start_indexes.size()
line_start_indexes.rend(),
char_index,
std::greater<std::size_t>()));
- return line_and_index(line, line <= 1 ? 0 : line_start_indexes[line - 2]);
+ return Line_and_index(line, line <= 1 ? 0 : line_start_indexes[line - 2]);
}
namespace
}
}
-source::line_and_column source::get_line_and_column(std::size_t char_index,
+Source::Line_and_column Source::get_line_and_column(std::size_t char_index,
std::size_t tab_size) const noexcept
{
auto line_and_start_index = get_line_and_start_index(char_index);
else
column++;
}
- return line_and_column(line_and_start_index.line, column);
+ return Line_and_column(line_and_start_index.line, column);
}
-std::ostream &operator<<(std::ostream &os, const location &v)
+std::ostream &operator<<(std::ostream &os, const Location &v)
{
os << v.to_string();
return os;
namespace
{
-enum class token_type
+enum class Token_type
{
eof,
l_bracket,
number,
};
-class tokenizer final
+class Tokenizer final
{
private:
std::size_t input_char_index;
static constexpr int eof = std::char_traits<char>::eof();
public:
- const source *const source;
- const parse_options options;
- location token_location;
- ast::value token_value;
- token_type token_type;
+ const Source *const source;
+ const Parse_options options;
+ Location token_location;
+ ast::Value token_value;
+ Token_type token_type;
private:
int peekc() const noexcept
int digit_char = peekc();
int digit_value = get_digit_value(digit_char, 0x10);
if(digit_value < 0)
- throw parse_error(location(source, input_char_index), "missing hex digit");
+ throw Parse_error(Location(source, input_char_index), "missing hex digit");
getc();
retval <<= 4;
retval |= digit_value;
}
public:
- tokenizer(const json::source *source, parse_options options)
+ Tokenizer(const json::Source *source, Parse_options options)
: input_char_index(0), source(source), options(options), token_location(), token_value()
{
next();
}
- ast::value get()
+ ast::Value get()
{
auto retval = token_value;
next();
{
while(is_whitespace(peekc()))
getc();
- token_location = location(source, input_char_index);
+ token_location = Location(source, input_char_index);
token_value = nullptr;
bool got_minus = false, got_plus = false;
if(peekc() == '-')
if(match_buffer_with_string(name, name_size, "null"))
{
token_value = nullptr;
- token_type = json::token_type::null_literal;
+ token_type = json::Token_type::null_literal;
return;
}
if(match_buffer_with_string(name, name_size, "false"))
{
token_value = false;
- token_type = json::token_type::false_literal;
+ token_type = json::Token_type::false_literal;
return;
}
if(match_buffer_with_string(name, name_size, "true"))
{
token_value = true;
- token_type = json::token_type::true_literal;
+ token_type = json::Token_type::true_literal;
return;
}
}
|| match_buffer_with_string(name, name_size, "NAN"))
{
token_value = std::numeric_limits<double>::quiet_NaN();
- token_type = json::token_type::number;
+ token_type = json::Token_type::number;
return;
}
if(match_buffer_with_string(name, name_size, "Infinity")
{
token_value = got_minus ? -std::numeric_limits<double>::infinity() :
std::numeric_limits<double>::infinity();
- token_type = json::token_type::number;
+ token_type = json::Token_type::number;
return;
}
}
- throw parse_error(token_location,
+ throw Parse_error(token_location,
(got_minus || got_plus ? "invalid number: " : "invalid identifier: ")
+ std::string(name, name_size));
}
getc();
got_any_digit = true;
if(is_digit(peekc()))
- throw parse_error(location(source, input_char_index),
+ throw Parse_error(Location(source, input_char_index),
"extra leading zero not allowed in numbers");
}
else
}
}
if(!got_any_digit)
- throw parse_error(location(source, input_char_index), "missing digit");
+ throw Parse_error(Location(source, input_char_index), "missing digit");
std::int64_t exponent = 0;
if(peekc() == 'e' || peekc() == 'E')
{
getc();
}
if(!is_digit(peekc()))
- throw parse_error(location(source, input_char_index), "missing digit");
+ throw Parse_error(Location(source, input_char_index), "missing digit");
while(is_digit(peekc()))
{
exponent *= 10;
auto value =
mantissa
* pow(util::soft_float::ExtendedFloat(static_cast<std::uint64_t>(10)), exponent);
- token_type = json::token_type::number;
+ token_type = json::Token_type::number;
token_value = static_cast<double>(value);
return;
}
while(true)
{
if(peekc() == eof || is_control_character(peekc()))
- throw parse_error(token_location, "string missing closing quote");
+ throw Parse_error(token_location, "string missing closing quote");
if(peekc() == quote)
{
getc();
}
if(peekc() == '\\')
{
- auto escape_location = location(source, input_char_index);
+ auto escape_location = Location(source, input_char_index);
getc();
switch(peekc())
{
std::uint32_t ch = parse_4_hex_digits();
if(ch >= 0xD800U && ch < 0xDC00U && peekc() == '\\')
{
- escape_location = location(source, input_char_index);
+ escape_location = Location(source, input_char_index);
getc();
if(peekc() == 'u')
{
value += getc();
break;
}
- throw parse_error(escape_location, "invalid escape sequence");
+ throw Parse_error(escape_location, "invalid escape sequence");
}
}
else
value += getc();
}
}
- token_type = json::token_type::string;
+ token_type = json::Token_type::string;
token_value = std::move(value);
return;
}
switch(peekc())
{
case eof:
- token_type = json::token_type::eof;
+ token_type = json::Token_type::eof;
token_value = nullptr;
return;
case '[':
getc();
- token_type = json::token_type::l_bracket;
+ token_type = json::Token_type::l_bracket;
token_value = nullptr;
return;
case ']':
getc();
- token_type = json::token_type::r_bracket;
+ token_type = json::Token_type::r_bracket;
token_value = nullptr;
return;
case '{':
getc();
- token_type = json::token_type::l_brace;
+ token_type = json::Token_type::l_brace;
token_value = nullptr;
return;
case '}':
getc();
- token_type = json::token_type::r_brace;
+ token_type = json::Token_type::r_brace;
token_value = nullptr;
return;
case ':':
getc();
- token_type = json::token_type::colon;
+ token_type = json::Token_type::colon;
token_value = nullptr;
return;
case ',':
getc();
- token_type = json::token_type::comma;
+ token_type = json::Token_type::comma;
token_value = nullptr;
return;
}
- throw parse_error(token_location, "invalid character");
+ throw Parse_error(token_location, "invalid character");
}
};
-ast::value parse_value(tokenizer &tokenizer)
+ast::Value parse_value(Tokenizer &tokenizer)
{
switch(tokenizer.token_type)
{
- case token_type::eof:
- throw parse_error(tokenizer.token_location, "missing value");
- case token_type::number:
- case token_type::string:
- case token_type::true_literal:
- case token_type::false_literal:
- case token_type::null_literal:
+ case Token_type::eof:
+ throw Parse_error(tokenizer.token_location, "missing value");
+ case Token_type::number:
+ case Token_type::string:
+ case Token_type::true_literal:
+ case Token_type::false_literal:
+ case Token_type::null_literal:
return tokenizer.get();
- case token_type::l_bracket:
+ case Token_type::l_bracket:
{
- std::vector<ast::value> values;
+ std::vector<ast::Value> values;
tokenizer.next();
- if(tokenizer.token_type == token_type::r_bracket)
+ if(tokenizer.token_type == Token_type::r_bracket)
{
tokenizer.next();
}
while(true)
{
values.push_back(parse_value(tokenizer));
- if(tokenizer.token_type == token_type::comma)
+ if(tokenizer.token_type == Token_type::comma)
{
tokenizer.next();
continue;
}
- if(tokenizer.token_type == token_type::r_bracket)
+ if(tokenizer.token_type == Token_type::r_bracket)
{
tokenizer.next();
break;
}
- throw parse_error(tokenizer.token_location, "missing , or ]");
+ throw Parse_error(tokenizer.token_location, "missing , or ]");
}
}
- return ast::array(std::move(values));
+ return ast::Array(std::move(values));
}
- case token_type::l_brace:
+ case Token_type::l_brace:
{
- std::unordered_map<std::string, ast::value> values;
+ std::unordered_map<std::string, ast::Value> values;
tokenizer.next();
- if(tokenizer.token_type == token_type::r_brace)
+ if(tokenizer.token_type == Token_type::r_brace)
{
tokenizer.next();
}
{
while(true)
{
- if(tokenizer.token_type != token_type::string)
- throw parse_error(tokenizer.token_location, "missing string");
- auto string_value = std::move(util::get<ast::string_value>(tokenizer.get()).value);
- if(tokenizer.token_type != token_type::colon)
- throw parse_error(tokenizer.token_location, "missing ':'");
+ if(tokenizer.token_type != Token_type::string)
+ throw Parse_error(tokenizer.token_location, "missing string");
+ auto string_value = std::move(util::get<ast::String_value>(tokenizer.get()).value);
+ if(tokenizer.token_type != Token_type::colon)
+ throw Parse_error(tokenizer.token_location, "missing ':'");
tokenizer.next();
values.emplace(std::move(string_value), parse_value(tokenizer));
- if(tokenizer.token_type == token_type::comma)
+ if(tokenizer.token_type == Token_type::comma)
{
tokenizer.next();
continue;
}
- if(tokenizer.token_type == token_type::r_brace)
+ if(tokenizer.token_type == Token_type::r_brace)
{
tokenizer.next();
break;
}
- throw parse_error(tokenizer.token_location, "missing ',' or '}'");
+ throw Parse_error(tokenizer.token_location, "missing ',' or '}'");
}
}
- return ast::object(std::move(values));
+ return ast::Object(std::move(values));
}
default:
break;
}
- throw parse_error(tokenizer.token_location, "token not allowed here");
+ throw Parse_error(tokenizer.token_location, "token not allowed here");
}
}
-ast::value parse(const source *source, parse_options options)
+ast::Value parse(const Source *source, Parse_options options)
{
- tokenizer tokenizer(source, options);
+ Tokenizer tokenizer(source, options);
auto retval = parse_value(tokenizer);
- if(tokenizer.token_type != token_type::eof)
- throw parse_error(tokenizer.token_location, "unexpected token");
+ if(tokenizer.token_type != Token_type::eof)
+ throw Parse_error(tokenizer.token_location, "unexpected token");
return retval;
}
}
{
namespace json
{
-struct source
+struct Source
{
std::string file_name;
std::shared_ptr<const char> contents; // use a shared_ptr so you can use mmap-ed memory
std::vector<std::size_t> line_start_indexes;
static std::vector<std::size_t> find_line_start_indexes(const char *contents,
std::size_t contents_size);
- source(source &&) = default;
- source(const source &) = delete;
- source &operator=(source &&) = default;
- source &operator=(const source &) = delete;
- source() : file_name(), contents(), contents_size(0), line_start_indexes()
+ Source(Source &&) = default;
+ Source(const Source &) = delete;
+ Source &operator=(Source &&) = default;
+ Source &operator=(const Source &) = delete;
+ Source() : file_name(), contents(), contents_size(0), line_start_indexes()
{
}
- explicit source(std::string file_name) noexcept : file_name(std::move(file_name)),
+ explicit Source(std::string file_name) noexcept : file_name(std::move(file_name)),
contents(),
contents_size(0),
line_start_indexes()
{
}
- source(std::string file_name,
+ Source(std::string file_name,
std::shared_ptr<const char> contents,
std::size_t contents_size) noexcept
: file_name(std::move(file_name)),
line_start_indexes(find_line_start_indexes(this->contents.get(), contents_size))
{
}
- source(std::string file_name, std::string contents_in)
+ Source(std::string file_name, std::string contents_in)
: file_name(file_name),
contents(),
contents_size(contents_in.size()),
auto str = std::make_shared<std::string>(std::move(contents_in));
contents = std::shared_ptr<const char>(str, str->data());
}
- source(std::string file_name, std::vector<char> contents_in)
+ Source(std::string file_name, std::vector<char> contents_in)
: file_name(file_name),
contents(),
contents_size(contents_in.size()),
auto str = std::make_shared<std::vector<char>>(std::move(contents_in));
contents = std::shared_ptr<const char>(str, str->data());
}
- source(std::string file_name, std::vector<unsigned char> contents_in)
+ Source(std::string file_name, std::vector<unsigned char> contents_in)
: file_name(file_name),
contents(),
contents_size(contents_in.size()),
{
return contents != nullptr;
}
- static source load_file(std::string file_name);
- static source load_stdin();
- struct line_and_index
+ static Source load_file(std::string file_name);
+ static Source load_stdin();
+ struct Line_and_index
{
std::size_t line;
std::size_t index;
- constexpr line_and_index() noexcept : line(), index()
+ constexpr Line_and_index() noexcept : line(), index()
{
}
- constexpr line_and_index(std::size_t line, std::size_t index) noexcept : line(line),
+ constexpr Line_and_index(std::size_t line, std::size_t index) noexcept : line(line),
index(index)
{
}
};
- struct line_and_column
+ struct Line_and_column
{
std::size_t line;
std::size_t column;
- constexpr line_and_column() noexcept : line(), column()
+ constexpr Line_and_column() noexcept : line(), column()
{
}
- constexpr line_and_column(std::size_t line, std::size_t column) noexcept : line(line),
+ constexpr Line_and_column(std::size_t line, std::size_t column) noexcept : line(line),
column(column)
{
}
std::string append_to_string(std::string buffer) const
{
- buffer = ast::number_value::append_unsigned_integer_to_string(line, std::move(buffer));
+ buffer = ast::Number_value::append_unsigned_integer_to_string(line, std::move(buffer));
buffer += ':';
buffer =
- ast::number_value::append_unsigned_integer_to_string(column, std::move(buffer));
+ ast::Number_value::append_unsigned_integer_to_string(column, std::move(buffer));
return buffer;
}
std::string to_string(std::string buffer = {}) const
buffer.clear();
return append_to_string(std::move(buffer));
}
- friend std::ostream &operator<<(std::ostream &os, const line_and_column &v);
+ friend std::ostream &operator<<(std::ostream &os, const Line_and_column &v);
};
static constexpr std::size_t default_tab_size = 8;
- line_and_index get_line_and_start_index(std::size_t char_index) const noexcept;
- line_and_column get_line_and_column(std::size_t char_index,
+ Line_and_index get_line_and_start_index(std::size_t char_index) const noexcept;
+ Line_and_column get_line_and_column(std::size_t char_index,
std::size_t tab_size = default_tab_size) const noexcept;
};
-struct location
+struct Location
{
- const source *source;
+ const Source *source;
std::size_t char_index;
- constexpr location() noexcept : source(nullptr), char_index(0)
+ constexpr Location() noexcept : source(nullptr), char_index(0)
{
}
- constexpr location(const json::source *source, std::size_t char_index) noexcept
+ constexpr Location(const json::Source *source, std::size_t char_index) noexcept
: source(source),
char_index(char_index)
{
}
- json::source::line_and_index get_line_and_start_index() const noexcept
+ json::Source::Line_and_index get_line_and_start_index() const noexcept
{
if(!source)
return {};
return source->get_line_and_start_index(char_index);
}
- json::source::line_and_column get_line_and_column(
- std::size_t tab_size = json::source::default_tab_size) const noexcept
+ json::Source::Line_and_column get_line_and_column(
+ std::size_t tab_size = json::Source::default_tab_size) const noexcept
{
if(!source)
return {};
return source->get_line_and_column(char_index, tab_size);
}
std::string to_string(std::string buffer = {},
- std::size_t tab_size = json::source::default_tab_size) const
+ std::size_t tab_size = json::Source::default_tab_size) const
{
buffer.clear();
return append_to_string(std::move(buffer));
}
std::string append_to_string(std::string buffer,
- std::size_t tab_size = json::source::default_tab_size) const
+ std::size_t tab_size = json::Source::default_tab_size) const
{
if(!source || source->file_name.empty())
buffer += "<unknown>";
buffer = get_line_and_column(tab_size).append_to_string(std::move(buffer));
return buffer;
}
- friend std::ostream &operator<<(std::ostream &os, const location &v);
+ friend std::ostream &operator<<(std::ostream &os, const Location &v);
};
-class parse_error : public std::runtime_error
+class Parse_error : public std::runtime_error
{
public:
- location location;
- parse_error(json::location location, const std::string &message)
+ Location location;
+ Parse_error(json::Location location, const std::string &message)
: runtime_error(location.to_string() + ": " + message)
{
}
- parse_error(json::location location, const char *message)
+ Parse_error(json::Location location, const char *message)
: runtime_error(location.to_string() + ": " + message)
{
}
};
-struct parse_options
+struct Parse_options
{
bool allow_infinity_and_nan;
bool allow_explicit_plus_sign_in_mantissa;
bool allow_single_quote_strings;
bool allow_number_to_start_with_dot;
- constexpr parse_options() noexcept : allow_infinity_and_nan(false),
+ constexpr Parse_options() noexcept : allow_infinity_and_nan(false),
allow_explicit_plus_sign_in_mantissa(false),
allow_single_quote_strings(false),
allow_number_to_start_with_dot(false)
{
}
- constexpr parse_options(bool allow_infinity_and_nan,
+ constexpr Parse_options(bool allow_infinity_and_nan,
bool allow_explicit_plus_sign_in_mantissa,
bool allow_single_quote_strings,
bool allow_number_to_start_with_dot) noexcept
allow_number_to_start_with_dot(allow_number_to_start_with_dot)
{
}
- static constexpr parse_options default_options() noexcept
+ static constexpr Parse_options default_options() noexcept
{
- return parse_options();
+ return Parse_options();
}
- static constexpr parse_options relaxed_options() noexcept
+ static constexpr Parse_options relaxed_options() noexcept
{
- return parse_options(true, true, true, true);
+ return Parse_options(true, true, true, true);
}
};
-ast::value parse(const source *source, parse_options options = parse_options::default_options());
+ast::Value parse(const Source *source, Parse_options options = Parse_options::default_options());
}
}
{
namespace spirv
{
-typedef std::uint32_t word;
-constexpr word magic_number = 0x07230203UL;
+typedef std::uint32_t Word;
+constexpr Word magic_number = 0x07230203UL;
}
}
}
template <typename T>
-struct invoke_is_reference_wrapper
+struct Invoke_is_reference_wrapper
{
static constexpr bool value = false;
};
template <typename T>
-struct invoke_is_reference_wrapper<std::reference_wrapper<T>>
+struct Invoke_is_reference_wrapper<std::reference_wrapper<T>>
{
static constexpr bool value = true;
};
typename... Args,
typename = int,
typename = typename std::enable_if<!std::is_base_of<T, typename std::decay<Arg1>::type>::value
- && invoke_is_reference_wrapper<
+ && Invoke_is_reference_wrapper<
typename std::decay<Arg1>::type>::value>::type>
constexpr decltype(auto) invoke_member_function_pointer(
Fn T::*fn,
typename = int,
typename = int,
typename = typename std::enable_if<!std::is_base_of<T, typename std::decay<Arg1>::type>::value
- && !invoke_is_reference_wrapper<
+ && !Invoke_is_reference_wrapper<
typename std::decay<Arg1>::type>::value>::type>
constexpr decltype(auto) invoke_member_function_pointer(
Fn T::*fn, Arg1 &&arg1, Args &&... args) noexcept(noexcept(((*std::forward<Arg1>(arg1))
typename Arg,
typename = int,
typename = typename std::enable_if<!std::is_base_of<T, typename std::decay<Arg>::type>::value
- && invoke_is_reference_wrapper<
+ && Invoke_is_reference_wrapper<
typename std::decay<Arg>::type>::value>::type>
constexpr decltype(auto) invoke_member_object_pointer(Fn T::*fn,
Arg &&arg) noexcept(noexcept(arg.get().*fn))
typename = int,
typename = int,
typename = typename std::enable_if<!std::is_base_of<T, typename std::decay<Arg>::type>::value
- && !invoke_is_reference_wrapper<
+ && !Invoke_is_reference_wrapper<
typename std::decay<Arg>::type>::value>::type>
constexpr decltype(auto) invoke_member_object_pointer(Fn T::*fn, Arg &&arg) noexcept(
noexcept((*std::forward<Arg>(arg)).*fn))
}
template <typename Fn, typename = void, typename... Args>
-struct invoke_result_helper
+struct Invoke_result_helper
{
static constexpr bool is_invokable = false;
static constexpr bool is_nothrow_invokable = false;
};
template <typename Fn, typename... Args>
-struct invoke_result_helper<Fn,
+struct Invoke_result_helper<Fn,
void_t<decltype(
invoke_helper(std::declval<Fn>(), std::declval<Args>()...))>,
Args...>
}
template <typename Fn, typename... Args>
-struct invoke_result : public detail::invoke_result_helper<Fn, void, Args...>
+struct invoke_result : public detail::Invoke_result_helper<Fn, void, Args...>
{
};
template <typename Fn, typename... Args>
struct is_invocable
- : public std::integral_constant<bool, detail::invoke_result_helper<Fn, Args...>::is_invokable>
+ : public std::integral_constant<bool, detail::Invoke_result_helper<Fn, Args...>::is_invokable>
{
};
template <typename R, typename Fn, typename... Args>
struct is_invocable_r
- : public std::integral_constant<bool,
- detail::invoke_result_helper<Fn, Args...>::template is_invokable_r<R>()>
+ : public std::
+ integral_constant<bool,
+ detail::Invoke_result_helper<Fn, Args...>::template is_invokable_r<R>()>
{
};
template <typename Fn, typename... Args>
struct is_nothrow_invocable
: public std::integral_constant<bool,
- detail::invoke_result_helper<Fn, Args...>::is_nothrow_invokable>
+ detail::Invoke_result_helper<Fn, Args...>::is_nothrow_invokable>
{
};
template <typename R, typename Fn, typename... Args>
struct is_nothrow_invocable_r
- : public std::
- integral_constant<bool,
- detail::invoke_result_helper<Fn, Args...>::template is_nothrow_invokable_r<R>()>
+ : public std::integral_constant<bool,
+ detail::Invoke_result_helper<Fn, Args...>::
+ template is_nothrow_invokable_r<R>()>
{
};
{
using std::swap;
template <typename T, typename U, bool Is_Void = std::is_void<T>::value || std::is_void<T>::value>
-class is_swappable_with
+class Is_swappable_with
{
private:
template <typename L,
};
template <typename T, typename U>
-class is_swappable_with<T, U, true>
+class Is_swappable_with<T, U, true>
{
public:
static constexpr bool value = false;
};
-template <typename T, typename U, bool Is_Swappable_With = is_swappable_with<T, U>::value>
-struct is_nothrow_swappable_with
+template <typename T, typename U, bool Is_Swappable_With = Is_swappable_with<T, U>::value>
+struct Is_nothrow_swappable_with
{
static constexpr bool value = noexcept(swap(std::declval<T>(), std::declval<U>()))
&& noexcept(swap(std::declval<U>(), std::declval<T>()));
};
template <typename T, typename U>
-struct is_nothrow_swappable_with<T, U, false>
+struct Is_nothrow_swappable_with<T, U, false>
{
static constexpr bool value = false;
};
struct is_swappable_with
: public std::integral_constant<bool,
vulkan_cpu_util_is_swappable_unrelated_namespace::
- is_swappable_with<T, U>::value>
+ Is_swappable_with<T, U>::value>
{
};
struct is_nothrow_swappable_with
: public std::integral_constant<bool,
vulkan_cpu_util_is_swappable_unrelated_namespace::
- is_nothrow_swappable_with<T, U>::value>
+ Is_nothrow_swappable_with<T, U>::value>
{
};
template <typename T,
bool Is_Trivially_Destructible = std::is_trivially_destructible<T>::value,
bool Is_Trivially_Copyable = std::is_trivially_copyable<T>::value>
-struct optional_base
+struct Optional_base
{
union
{
alignas(T) char empty_value[sizeof(T)];
};
bool is_full;
- constexpr optional_base() noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base() noexcept : empty_value{}, is_full(false)
{
}
- constexpr optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
{
}
void reset() noexcept
is_full = true;
return full_value;
}
- optional_base(const optional_base &rt) noexcept(std::is_nothrow_copy_constructible<T>::value)
+ Optional_base(const Optional_base &rt) noexcept(std::is_nothrow_copy_constructible<T>::value)
: empty_value{}, is_full(false)
{
if(rt.is_full)
emplace(rt.full_value);
}
- optional_base(optional_base &&rt) noexcept(std::is_nothrow_move_constructible<T>::value)
+ Optional_base(Optional_base &&rt) noexcept(std::is_nothrow_move_constructible<T>::value)
: empty_value{}, is_full(false)
{
if(rt.is_full)
}
template <typename... Types,
typename = typename std::enable_if<std::is_constructible<T, Types...>::value>::type>
- constexpr explicit optional_base(in_place_t, Types &&... args) noexcept(
+ constexpr explicit Optional_base(in_place_t, Types &&... args) noexcept(
std::is_nothrow_constructible<T, Types...>::value)
: full_value(std::forward<Types>(args)...), is_full(true)
{
typename... Types,
typename = typename std::
enable_if<std::is_constructible<T, std::initializer_list<U>, Types...>::value>::type>
- constexpr explicit optional_base(
+ constexpr explicit Optional_base(
in_place_t,
std::initializer_list<U> init_list,
Types &&... args) noexcept(std::is_nothrow_constructible<T, Types...>::value)
: full_value(init_list, std::forward<Types>(args)...), is_full(true)
{
}
- ~optional_base()
+ ~Optional_base()
{
reset();
}
- optional_base &operator=(const optional_base &rt) noexcept(
+ Optional_base &operator=(const Optional_base &rt) noexcept(
std::is_nothrow_copy_assignable<T>::value)
{
if(!rt.is_full)
full_value = rt.full_value;
return *this;
}
- optional_base &operator=(optional_base &&rt) noexcept(std::is_nothrow_move_assignable<T>::value)
+ Optional_base &operator=(Optional_base &&rt) noexcept(std::is_nothrow_move_assignable<T>::value)
{
if(!rt.is_full)
reset();
};
template <typename T>
-struct optional_base<T, true, false>
+struct Optional_base<T, true, false>
{
union
{
alignas(T) char empty_value[sizeof(T)];
};
bool is_full;
- constexpr optional_base() noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base() noexcept : empty_value{}, is_full(false)
{
}
- constexpr optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
{
}
void reset() noexcept
is_full = true;
return full_value;
}
- optional_base(const optional_base &rt) noexcept(std::is_nothrow_copy_constructible<T>::value)
+ Optional_base(const Optional_base &rt) noexcept(std::is_nothrow_copy_constructible<T>::value)
: empty_value{}, is_full(false)
{
if(rt.is_full)
emplace(rt.full_value);
}
- optional_base(optional_base &&rt) noexcept(std::is_nothrow_move_constructible<T>::value)
+ Optional_base(Optional_base &&rt) noexcept(std::is_nothrow_move_constructible<T>::value)
: empty_value{}, is_full(false)
{
if(rt.is_full)
}
template <typename... Types,
typename = typename std::enable_if<std::is_constructible<T, Types...>::value>::type>
- constexpr explicit optional_base(in_place_t, Types &&... args) noexcept(
+ constexpr explicit Optional_base(in_place_t, Types &&... args) noexcept(
std::is_nothrow_constructible<T, Types...>::value)
: full_value(std::forward<Types>(args)...), is_full(true)
{
typename... Types,
typename = typename std::
enable_if<std::is_constructible<T, std::initializer_list<U>, Types...>::value>::type>
- constexpr explicit optional_base(
+ constexpr explicit Optional_base(
in_place_t,
std::initializer_list<U> init_list,
Types &&... args) noexcept(std::is_nothrow_constructible<T, Types...>::value)
: full_value(init_list, std::forward<Types>(args)...), is_full(true)
{
}
- ~optional_base() = default;
- optional_base &operator=(const optional_base &rt) noexcept(
+ ~Optional_base() = default;
+ Optional_base &operator=(const Optional_base &rt) noexcept(
std::is_nothrow_copy_assignable<T>::value)
{
if(!rt.is_full)
full_value = rt.full_value;
return *this;
}
- optional_base &operator=(optional_base &&rt) noexcept(std::is_nothrow_move_assignable<T>::value)
+ Optional_base &operator=(Optional_base &&rt) noexcept(std::is_nothrow_move_assignable<T>::value)
{
if(!rt.is_full)
reset();
};
template <typename T>
-struct optional_base<T, true, true>
+struct Optional_base<T, true, true>
{
union
{
alignas(T) char empty_value[sizeof(T)];
};
bool is_full;
- constexpr optional_base() noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base() noexcept : empty_value{}, is_full(false)
{
}
- constexpr optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
+ constexpr Optional_base(nullopt_t) noexcept : empty_value{}, is_full(false)
{
}
void reset() noexcept
is_full = true;
return full_value;
}
- constexpr optional_base(const optional_base &rt) noexcept = default;
- constexpr optional_base(optional_base &&rt) noexcept = default;
+ constexpr Optional_base(const Optional_base &rt) noexcept = default;
+ constexpr Optional_base(Optional_base &&rt) noexcept = default;
template <typename... Types,
typename = typename std::enable_if<std::is_constructible<T, Types...>::value>::type>
- constexpr explicit optional_base(in_place_t, Types &&... args) noexcept(
+ constexpr explicit Optional_base(in_place_t, Types &&... args) noexcept(
std::is_nothrow_constructible<T, Types...>::value)
: full_value(std::forward<Types>(args)...), is_full(true)
{
typename... Types,
typename = typename std::
enable_if<std::is_constructible<T, std::initializer_list<U>, Types...>::value>::type>
- constexpr explicit optional_base(
+ constexpr explicit Optional_base(
in_place_t,
std::initializer_list<U> init_list,
Types &&... args) noexcept(std::is_nothrow_constructible<T, Types...>::value)
: full_value(init_list, std::forward<Types>(args)...), is_full(true)
{
}
- ~optional_base() = default;
- optional_base &operator=(const optional_base &rt) noexcept = default;
- optional_base &operator=(optional_base &&rt) noexcept = default;
+ ~Optional_base() = default;
+ Optional_base &operator=(const Optional_base &rt) noexcept = default;
+ Optional_base &operator=(Optional_base &&rt) noexcept = default;
};
}
}
template <typename T>
-class optional : private detail::optional_base<T>
+class optional : private detail::Optional_base<T>
{
private:
- typedef detail::optional_base<T> base;
- using base::is_full;
- using base::full_value;
+ typedef detail::Optional_base<T> Base;
+ using Base::is_full;
+ using Base::full_value;
public:
- using base::base;
- using base::operator=;
- using base::reset;
- using base::emplace;
+ using Base::Base;
+ using Base::operator=;
+ using Base::reset;
+ using Base::emplace;
constexpr optional() noexcept = default;
template <typename U,
typename = typename std::
enable_if<detail::optional_needs_conversion_constructors<T, U, const U &>()
&& std::is_convertible<const U &, T>::value>::type>
optional(const optional<U> &rt) noexcept(std::is_nothrow_constructible<T, const U &>::value)
- : base()
+ : Base()
{
if(rt)
emplace(*rt);
typename = void>
explicit optional(const optional<U> &rt) noexcept(
std::is_nothrow_constructible<T, const U &>::value)
- : base()
+ : Base()
{
if(rt)
emplace(*rt);
typename std::enable_if<detail::optional_needs_conversion_constructors<T, U, U &&>()
&& std::is_convertible<U &&, T>::value>::type>
optional(optional<U> &&rt) noexcept(std::is_nothrow_constructible<T, U &&>::value)
- : base()
+ : Base()
{
if(rt)
emplace(std::move(*rt));
&& !std::is_convertible<U &&, T>::value>::type,
typename = void>
explicit optional(optional<U> &&rt) noexcept(std::is_nothrow_constructible<T, U &&>::value)
- : base()
+ : Base()
{
if(rt)
emplace(std::move(*rt));
&& std::is_convertible<U &&, T>::value>::type,
typename = void>
constexpr optional(U &&value) noexcept(std::is_nothrow_constructible<T, U &&>::value)
- : base(in_place, std::forward<U>(value))
+ : Base(in_place, std::forward<U>(value))
{
}
template <typename U,
&& !std::is_same<typename std::decay<U>::type, optional>::value
&& !std::is_convertible<U &&, T>::value>::type>
explicit constexpr optional(U &&value) noexcept(std::is_nothrow_constructible<T, U &&>::value)
- : base(in_place, std::forward<U>(value))
+ : Base(in_place, std::forward<U>(value))
{
}
template <typename U = T,
namespace detail
{
-struct variant_base_construct_tag
+struct Variant_base_construct_tag
{
- explicit variant_base_construct_tag() = default;
+ explicit Variant_base_construct_tag() = default;
};
template <typename T>
-struct variant_identity_type
+struct Variant_identity_type
{
typedef T type;
};
template <typename... Types>
-struct variant_hypothetical_overload_set;
+struct Variant_hypothetical_overload_set;
template <typename T, typename... Types>
-struct variant_hypothetical_overload_set<T, Types...>
- : public variant_hypothetical_overload_set<Types...>
+struct Variant_hypothetical_overload_set<T, Types...>
+ : public Variant_hypothetical_overload_set<Types...>
{
- using variant_hypothetical_overload_set<Types...>::fn;
- static variant_identity_type<T> fn(T); // not implemented
+ using Variant_hypothetical_overload_set<Types...>::fn;
+ static Variant_identity_type<T> fn(T); // not implemented
};
template <>
-struct variant_hypothetical_overload_set<>
+struct Variant_hypothetical_overload_set<>
{
static void fn(); // not implemented
};
template <typename T>
-struct variant_is_equals_comparable
+struct Variant_is_equals_comparable
{
private:
static std::false_type fn(...);
};
template <typename T>
-struct variant_is_less_comparable
+struct Variant_is_less_comparable
{
private:
static std::false_type fn(...);
};
template <typename T>
-struct variant_is_nothrow_equals_comparable
+struct Variant_is_nothrow_equals_comparable
{
private:
static std::false_type fn(...);
};
template <typename T>
-struct variant_is_nothrow_less_comparable
+struct Variant_is_nothrow_less_comparable
{
private:
static std::false_type fn(...);
}
template <bool Is_Trivially_Destructible, typename... Types>
-union variant_values_implementation
+union Variant_values_implementation
{
char value;
static constexpr bool is_copy_constructible = true;
static constexpr bool is_less_comparable = true;
static constexpr bool is_nothrow_equals_comparable = true;
static constexpr bool is_nothrow_less_comparable = true;
- variant_values_implementation() = delete;
+ Variant_values_implementation() = delete;
template <std::size_t index>
- constexpr variant_values_implementation(in_place_index_t<index>) noexcept : value()
+ constexpr Variant_values_implementation(in_place_index_t<index>) noexcept : value()
{
}
template <typename U>
{
return variant_npos;
}
- void copy_construct(const variant_values_implementation &rt, std::size_t index) noexcept
+ void copy_construct(const Variant_values_implementation &rt, std::size_t index) noexcept
{
}
- void move_construct(variant_values_implementation &&rt, std::size_t index) noexcept
+ void move_construct(Variant_values_implementation &&rt, std::size_t index) noexcept
{
}
- void copy_assign(const variant_values_implementation &rt, std::size_t index) noexcept
+ void copy_assign(const Variant_values_implementation &rt, std::size_t index) noexcept
{
}
- void move_assign(variant_values_implementation &&rt, std::size_t index) noexcept
+ void move_assign(Variant_values_implementation &&rt, std::size_t index) noexcept
{
}
void destruct(std::size_t index) noexcept
{
}
- void swap(variant_values_implementation &rt, std::size_t index) noexcept
+ void swap(Variant_values_implementation &rt, std::size_t index) noexcept
{
}
- bool is_equal(const variant_values_implementation &rt, std::size_t index) const noexcept
+ bool is_equal(const Variant_values_implementation &rt, std::size_t index) const noexcept
{
return true;
}
- bool is_less(const variant_values_implementation &rt, std::size_t index) const noexcept
+ bool is_less(const Variant_values_implementation &rt, std::size_t index) const noexcept
{
return false;
}
};
template <typename... Types>
-using variant_values =
- variant_values_implementation<variant_is_trivially_destructible<Types...>(), Types...>;
+using Variant_values =
+ Variant_values_implementation<variant_is_trivially_destructible<Types...>(), Types...>;
#define VULKAN_CPU_UTIL_VARIANT_VALUES(Is_Trivially_Destructible, Destructor) \
template <typename T, typename... Types> \
- union variant_values_implementation<Is_Trivially_Destructible, T, Types...> \
+ union Variant_values_implementation<Is_Trivially_Destructible, T, Types...> \
{ \
- typedef T type_0; \
+ typedef T Type_0; \
static_assert(!std::is_void<T>::value, "invalid variant member type"); \
static_assert(!std::is_reference<T>::value, "invalid variant member type"); \
static_assert(!std::is_array<T>::value, "invalid variant member type"); \
static_assert(!std::is_volatile<T>::value, "invalid variant member type"); \
static_assert(std::is_object<T>::value, "invalid variant member type"); \
T current_value; \
- variant_values_implementation<Is_Trivially_Destructible, Types...> other_values; \
+ Variant_values_implementation<Is_Trivially_Destructible, Types...> other_values; \
static constexpr bool is_copy_constructible = \
std::is_copy_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_copy_constructible; \
static constexpr bool is_move_constructible = \
std::is_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_move_constructible; \
static constexpr bool is_nothrow_copy_constructible = \
std::is_nothrow_copy_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_copy_constructible; \
static constexpr bool is_nothrow_move_constructible = \
std::is_nothrow_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_move_constructible; \
static constexpr bool is_copy_assignable = \
std::is_copy_assignable<T>::value && std::is_copy_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_copy_assignable; \
static constexpr bool is_move_assignable = \
std::is_move_assignable<T>::value && std::is_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_move_assignable; \
static constexpr bool is_nothrow_copy_assignable = \
std::is_nothrow_copy_assignable<T>::value \
&& std::is_nothrow_copy_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_copy_assignable; \
static constexpr bool is_nothrow_move_assignable = \
std::is_nothrow_move_assignable<T>::value \
&& std::is_nothrow_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_move_assignable; \
static constexpr bool is_swappable = \
is_swappable_v<T> && std::is_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, Types...>::is_swappable; \
+ && Variant_values_implementation<Is_Trivially_Destructible, Types...>::is_swappable; \
static constexpr bool is_nothrow_swappable = \
is_nothrow_swappable_v<T> && std::is_nothrow_move_constructible<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_swappable; \
static constexpr bool is_equals_comparable = \
- variant_is_equals_comparable<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ Variant_is_equals_comparable<T>::value \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_equals_comparable; \
static constexpr bool is_less_comparable = \
- variant_is_less_comparable<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ Variant_is_less_comparable<T>::value \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_less_comparable; \
static constexpr bool is_nothrow_equals_comparable = \
- variant_is_nothrow_equals_comparable<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ Variant_is_nothrow_equals_comparable<T>::value \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_equals_comparable; \
static constexpr bool is_nothrow_less_comparable = \
- variant_is_nothrow_less_comparable<T>::value \
- && variant_values_implementation<Is_Trivially_Destructible, \
+ Variant_is_nothrow_less_comparable<T>::value \
+ && Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::is_nothrow_less_comparable; \
template < \
typename T2 = T, \
typename = typename std::enable_if<std::is_default_constructible<T2>::value>::type> \
- constexpr variant_values_implementation() noexcept( \
+ constexpr Variant_values_implementation() noexcept( \
std::is_nothrow_default_constructible<T2>::value) \
: current_value() \
{ \
template < \
typename... Args, \
typename = typename std::enable_if<std::is_constructible<T, Args...>::value>::type> \
- constexpr variant_values_implementation(in_place_index_t<0>, Args &&... args) noexcept( \
+ constexpr Variant_values_implementation(in_place_index_t<0>, Args &&... args) noexcept( \
std::is_nothrow_constructible<T, Args...>::value) \
: current_value(std::forward<Args>(args)...) \
{ \
typename = typename std:: \
enable_if<index != 0 \
&& std:: \
- is_constructible<variant_values_implementation<Is_Trivially_Destructible, \
+ is_constructible<Variant_values_implementation<Is_Trivially_Destructible, \
Types...>, \
in_place_index_t<index - 1>, \
Args...>::value>::type> \
- constexpr variant_values_implementation(in_place_index_t<index>, Args &&... args) noexcept( \
- std::is_nothrow_constructible<variant_values_implementation<Is_Trivially_Destructible, \
+ constexpr Variant_values_implementation(in_place_index_t<index>, Args &&... args) noexcept( \
+ std::is_nothrow_constructible<Variant_values_implementation<Is_Trivially_Destructible, \
Types...>, \
in_place_index_t<index - 1>, \
Args...>::value) \
typename = typename std::enable_if<std::is_constructible<T, \
std::initializer_list<U>, \
Args...>::value>::type> \
- constexpr variant_values_implementation( \
+ constexpr Variant_values_implementation( \
in_place_index_t<0>, \
std::initializer_list<U> il, \
Args &&... args) noexcept(std::is_nothrow_constructible<T, \
static constexpr std::size_t index_from_type() noexcept \
{ \
std::size_t next = \
- variant_values_implementation<Is_Trivially_Destructible, \
+ Variant_values_implementation<Is_Trivially_Destructible, \
Types...>::template index_from_type<U>(); \
if(std::is_same<U, T>::value && next == variant_npos) \
return 0; \
return variant_npos; \
return next + 1; \
} \
- void copy_construct(const variant_values_implementation &rt, \
+ void copy_construct(const Variant_values_implementation &rt, \
std::size_t index) noexcept(is_nothrow_copy_constructible) \
{ \
if(index == 0) \
else \
other_values.copy_construct(rt.other_values, index - 1); \
} \
- void move_construct(variant_values_implementation &&rt, \
+ void move_construct(Variant_values_implementation &&rt, \
std::size_t index) noexcept(is_nothrow_move_constructible) \
{ \
if(index == 0) \
else \
other_values.move_construct(std::move(rt.other_values), index - 1); \
} \
- void copy_assign(const variant_values_implementation &rt, \
+ void copy_assign(const Variant_values_implementation &rt, \
std::size_t index) noexcept(is_nothrow_copy_assignable) \
{ \
if(index == 0) \
else \
other_values.copy_assign(rt.other_values, index - 1); \
} \
- void move_assign(variant_values_implementation &&rt, \
+ void move_assign(Variant_values_implementation &&rt, \
std::size_t index) noexcept(is_nothrow_move_assignable) \
{ \
if(index == 0) \
else \
other_values.destruct(index - 1); \
} \
- void swap(variant_values_implementation &rt, \
+ void swap(Variant_values_implementation &rt, \
std::size_t index) noexcept(is_nothrow_swappable) \
{ \
using std::swap; \
else \
other_values.swap(rt.other_values, index - 1); \
} \
- bool is_equal(const variant_values_implementation &rt, std::size_t index) const \
+ bool is_equal(const Variant_values_implementation &rt, std::size_t index) const \
noexcept(is_nothrow_equals_comparable) \
{ \
if(index == 0) \
return static_cast<bool>(current_value == rt.current_value); \
return other_values.is_equal(rt.other_values, index - 1); \
} \
- bool is_less(const variant_values_implementation &rt, std::size_t index) const \
+ bool is_less(const Variant_values_implementation &rt, std::size_t index) const \
noexcept(is_nothrow_less_comparable) \
{ \
if(index == 0) \
Destructor \
};
-VULKAN_CPU_UTIL_VARIANT_VALUES(true, ~variant_values_implementation() = default;)
-VULKAN_CPU_UTIL_VARIANT_VALUES(false, ~variant_values_implementation(){})
+VULKAN_CPU_UTIL_VARIANT_VALUES(true, ~Variant_values_implementation() = default;)
+VULKAN_CPU_UTIL_VARIANT_VALUES(false, ~Variant_values_implementation(){})
#undef VULKAN_CPU_UTIL_VARIANT_VALUES
template <std::size_t Index, typename... Types>
-struct variant_get;
+struct Variant_get;
template <std::size_t Index, typename T, typename... Types>
-struct variant_get<Index, T, Types...>
+struct Variant_get<Index, T, Types...>
{
- static constexpr auto get(const variant_values<T, Types...> &values) noexcept
- -> decltype(variant_get<Index - 1, Types...>::get(values.other_values))
+ static constexpr auto get(const Variant_values<T, Types...> &values) noexcept
+ -> decltype(Variant_get<Index - 1, Types...>::get(values.other_values))
{
- return variant_get<Index - 1, Types...>::get(values.other_values);
+ return Variant_get<Index - 1, Types...>::get(values.other_values);
}
- static constexpr auto get(variant_values<T, Types...> &values) noexcept
- -> decltype(variant_get<Index - 1, Types...>::get(values.other_values))
+ static constexpr auto get(Variant_values<T, Types...> &values) noexcept
+ -> decltype(Variant_get<Index - 1, Types...>::get(values.other_values))
{
- return variant_get<Index - 1, Types...>::get(values.other_values);
+ return Variant_get<Index - 1, Types...>::get(values.other_values);
}
- static constexpr auto get(const variant_values<T, Types...> &&values) noexcept
- -> decltype(variant_get<Index - 1, Types...>::get(std::move(values.other_values)))
+ static constexpr auto get(const Variant_values<T, Types...> &&values) noexcept
+ -> decltype(Variant_get<Index - 1, Types...>::get(std::move(values.other_values)))
{
- return variant_get<Index - 1, Types...>::get(std::move(values.other_values));
+ return Variant_get<Index - 1, Types...>::get(std::move(values.other_values));
}
- static constexpr auto get(variant_values<T, Types...> &&values) noexcept
- -> decltype(variant_get<Index - 1, Types...>::get(std::move(values.other_values)))
+ static constexpr auto get(Variant_values<T, Types...> &&values) noexcept
+ -> decltype(Variant_get<Index - 1, Types...>::get(std::move(values.other_values)))
{
- return variant_get<Index - 1, Types...>::get(std::move(values.other_values));
+ return Variant_get<Index - 1, Types...>::get(std::move(values.other_values));
}
};
template <typename T, typename... Types>
-struct variant_get<0, T, Types...>
+struct Variant_get<0, T, Types...>
{
- static constexpr const T &get(const variant_values<T, Types...> &values) noexcept
+ static constexpr const T &get(const Variant_values<T, Types...> &values) noexcept
{
return values.current_value;
}
- static constexpr T &get(variant_values<T, Types...> &values) noexcept
+ static constexpr T &get(Variant_values<T, Types...> &values) noexcept
{
return values.current_value;
}
- static constexpr const T &&get(const variant_values<T, Types...> &&values) noexcept
+ static constexpr const T &&get(const Variant_values<T, Types...> &&values) noexcept
{
return std::move(values.current_value);
}
- static constexpr T &&get(variant_values<T, Types...> &&values) noexcept
+ static constexpr T &&get(Variant_values<T, Types...> &&values) noexcept
{
return std::move(values.current_value);
}
typename... Types, \
typename... Args> \
constexpr Return_Type variant_dispatch_helper_dispatch_function( \
- Fn &&fn, Const variant_values<Types...> Ref values, Args &&... args) \
+ Fn &&fn, Const Variant_values<Types...> Ref values, Args &&... args) \
{ \
- return std::forward<Fn>(fn)(variant_get<Index, Types...>::get( \
- std::forward<Const variant_values<Types...> Ref>(values)), \
+ return std::forward<Fn>(fn)(Variant_get<Index, Types...>::get( \
+ std::forward<Const Variant_values<Types...> Ref>(values)), \
std::forward<Args>(args)...); \
} \
\
typename Return_Type = typename std::common_type<decltype(std::declval<Fn>()( \
std::declval<Const Types Ref>(), std::declval<Args>()...))...>::type> \
constexpr Return_Type variant_dispatch_helper(Fn &&fn, \
- Const variant_values<Types...> Ref values, \
+ Const Variant_values<Types...> Ref values, \
std::size_t index, \
std::index_sequence<Indexes...>, \
Args &&... args) \
{ \
- typedef Return_Type (*Dispatch_Function)( \
- Fn && fn, Const variant_values<Types...> Ref values, Args && ... args); \
- const Dispatch_Function dispatch_functions[sizeof...(Types)] = { \
- static_cast<Dispatch_Function>( \
+ typedef Return_Type (*Dispatch_function)( \
+ Fn && fn, Const Variant_values<Types...> Ref values, Args && ... args); \
+ const Dispatch_function dispatch_functions[sizeof...(Types)] = { \
+ static_cast<Dispatch_function>( \
&variant_dispatch_helper_dispatch_function<Indexes, Return_Type>)..., \
}; \
if(index < sizeof...(Types)) \
return dispatch_functions[index]( \
std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
std::forward<Args>(args)...); \
throw bad_variant_access(); \
} \
\
template <typename Fn, typename... Args, typename... Types> \
constexpr auto variant_dispatch( \
- Fn &&fn, Const variant_values<Types...> Ref values, std::size_t index, Args &&... args) \
+ Fn &&fn, Const Variant_values<Types...> Ref values, std::size_t index, Args &&... args) \
->decltype( \
variant_dispatch_helper(std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
index, \
std::index_sequence_for<Types...>{}, \
std::forward<Args>(args)...)) \
{ \
return variant_dispatch_helper(std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
index, \
std::index_sequence_for<Types...>{}, \
std::forward<Args>(args)...); \
std::declval<Const Types Ref>(), std::declval<Args>()...))...>::type> \
constexpr Return_Type variant_dispatch_helper_nothrow( \
Fn &&fn, \
- Const variant_values<Types...> Ref values, \
+ Const Variant_values<Types...> Ref values, \
std::size_t index, \
std::index_sequence<Indexes...>, \
Args &&... args) \
{ \
- typedef Return_Type (*Dispatch_Function)( \
- Fn && fn, Const variant_values<Types...> Ref values, Args && ... args); \
- const Dispatch_Function dispatch_functions[sizeof...(Types)] = { \
- static_cast<Dispatch_Function>( \
+ typedef Return_Type (*Dispatch_function)( \
+ Fn && fn, Const Variant_values<Types...> Ref values, Args && ... args); \
+ const Dispatch_function dispatch_functions[sizeof...(Types)] = { \
+ static_cast<Dispatch_function>( \
&variant_dispatch_helper_dispatch_function<Indexes, Return_Type>)..., \
}; \
if(index < sizeof...(Types)) \
return dispatch_functions[index]( \
std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
std::forward<Args>(args)...); \
return {}; \
} \
\
template <typename Fn, typename... Args, typename... Types> \
constexpr auto variant_dispatch_nothrow( \
- Fn &&fn, Const variant_values<Types...> Ref values, std::size_t index, Args &&... args) \
+ Fn &&fn, Const Variant_values<Types...> Ref values, std::size_t index, Args &&... args) \
->decltype(variant_dispatch_helper_nothrow( \
std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
index, \
std::index_sequence_for<Types...>{}, \
std::forward<Args>(args)...)) \
{ \
return variant_dispatch_helper_nothrow( \
std::forward<Fn>(fn), \
- std::forward<Const variant_values<Types...> Ref>(values), \
+ std::forward<Const Variant_values<Types...> Ref>(values), \
index, \
std::index_sequence_for<Types...>{}, \
std::forward<Args>(args)...); \
#undef VULKAN_CPU_UTIL_VARIANT_DISPATCH
template <std::size_t Type_Count>
-struct variant_index_type
+struct Variant_index_type
{
static constexpr std::size_t total_state_count =
Type_Count + 1; // for valueless-by-exception state
total_state_count <= std::numeric_limits<unsigned long long>::max();
typedef
typename std::conditional<is_unsigned_long_long_good, unsigned long long, std::size_t>::type
- unsigned_long_long_or_larger;
+ Unsigned_long_long_or_larger;
typedef typename std::conditional<is_unsigned_long_good,
unsigned long,
- unsigned_long_long_or_larger>::type unsigned_long_or_larger;
- typedef typename std::conditional<is_unsigned_good, unsigned, unsigned_long_or_larger>::type
- unsigned_or_larger;
+ Unsigned_long_long_or_larger>::type Unsigned_long_or_larger;
+ typedef typename std::conditional<is_unsigned_good, unsigned, Unsigned_long_or_larger>::type
+ Unsigned_or_larger;
typedef
- typename std::conditional<is_unsigned_short_good, unsigned short, unsigned_or_larger>::type
- unsigned_short_or_larger;
+ typename std::conditional<is_unsigned_short_good, unsigned short, Unsigned_or_larger>::type
+ Unsigned_short_or_larger;
typedef typename std::conditional<is_unsigned_char_good,
unsigned char,
- unsigned_short_or_larger>::type type;
+ Unsigned_short_or_larger>::type type;
static constexpr type npos = variant_npos;
type index_value;
- constexpr variant_index_type() = delete;
- constexpr explicit variant_index_type(std::size_t index_value) noexcept
+ constexpr Variant_index_type() = delete;
+ constexpr explicit Variant_index_type(std::size_t index_value) noexcept
: index_value(index_value)
{
}
bool Is_Copy_Assignable,
bool Is_Move_Assignable,
typename... Types>
-struct variant_base;
+struct Variant_base;
#define VULKAN_CPU_UTIL_VARIANT_BASE_DESTRUCTOR_false \
- ~variant_base() \
+ ~Variant_base() \
{ \
values.destruct(index_value.get()); \
}
-#define VULKAN_CPU_UTIL_VARIANT_BASE_DESTRUCTOR_true ~variant_base() = default;
+#define VULKAN_CPU_UTIL_VARIANT_BASE_DESTRUCTOR_true ~Variant_base() = default;
#define VULKAN_CPU_UTIL_VARIANT_BASE_COPY_CONSTRUCTOR_true \
- variant_base(const variant_base &rt) noexcept( \
- detail::variant_values<Types...>::is_nothrow_copy_constructible) \
+ Variant_base(const Variant_base &rt) noexcept( \
+ Variant_values<Types...>::is_nothrow_copy_constructible) \
: values(in_place_index<variant_npos>), index_value(variant_npos) \
{ \
values.copy_construct(rt.values, rt.index_value.get()); \
}
#define VULKAN_CPU_UTIL_VARIANT_BASE_COPY_CONSTRUCTOR_false \
- variant_base(const variant_base &rt) = delete;
+ Variant_base(const Variant_base &rt) = delete;
#define VULKAN_CPU_UTIL_VARIANT_BASE_MOVE_CONSTRUCTOR_true \
- variant_base(variant_base &&rt) noexcept( \
- detail::variant_values<Types...>::is_nothrow_move_constructible) \
+ Variant_base(Variant_base &&rt) noexcept( \
+ Variant_values<Types...>::is_nothrow_move_constructible) \
: values(in_place_index<variant_npos>), index_value(variant_npos) \
{ \
values.move_construct(std::move(rt.values), rt.index_value.get()); \
}
#define VULKAN_CPU_UTIL_VARIANT_BASE_MOVE_CONSTRUCTOR_false \
- variant_base(variant_base &&rt) = delete;
+ Variant_base(Variant_base &&rt) = delete;
#define VULKAN_CPU_UTIL_VARIANT_BASE_COPY_ASSIGN_OP_true \
- variant_base &operator=(const variant_base &rt) noexcept( \
- detail::variant_values<Types...>::is_nothrow_copy_assignable) \
+ Variant_base &operator=(const Variant_base &rt) noexcept( \
+ Variant_values<Types...>::is_nothrow_copy_assignable) \
{ \
if(index_value.get() == rt.index_value.get()) \
{ \
}
#define VULKAN_CPU_UTIL_VARIANT_BASE_COPY_ASSIGN_OP_false \
- variant_base &operator=(const variant_base &rt) = delete;
+ Variant_base &operator=(const Variant_base &rt) = delete;
#define VULKAN_CPU_UTIL_VARIANT_BASE_MOVE_ASSIGN_OP_true \
- variant_base &operator=(variant_base &&rt) noexcept( \
- detail::variant_values<Types...>::is_nothrow_move_assignable) \
+ Variant_base &operator=(Variant_base &&rt) noexcept( \
+ Variant_values<Types...>::is_nothrow_move_assignable) \
{ \
if(index_value.get() == rt.index_value.get()) \
{ \
}
#define VULKAN_CPU_UTIL_VARIANT_BASE_MOVE_ASSIGN_OP_false \
- variant_base &operator=(variant_base &&rt) = delete;
+ Variant_base &operator=(Variant_base &&rt) = delete;
#define VULKAN_CPU_UTIL_VARIANT_BASE0(Is_Trivially_Destructible, \
Is_Copy_Constructible, \
Is_Copy_Assignable, \
Is_Move_Assignable) \
template <typename... Types> \
- struct variant_base<Is_Trivially_Destructible, \
+ struct Variant_base<Is_Trivially_Destructible, \
Is_Copy_Constructible, \
Is_Move_Constructible, \
Is_Copy_Assignable, \
Is_Move_Assignable, \
Types...> \
{ \
- detail::variant_values<Types...> values; \
- detail::variant_index_type<sizeof...(Types)> index_value; \
+ Variant_values<Types...> values; \
+ Variant_index_type<sizeof...(Types)> index_value; \
template <typename... Args> \
- constexpr variant_base( \
- variant_base_construct_tag, \
+ constexpr Variant_base( \
+ Variant_base_construct_tag, \
std::size_t index_value, \
Args &&... args) noexcept(noexcept(new(std::declval<void *>()) \
- detail::variant_values<Types...>( \
+ Variant_values<Types...>( \
std::declval<Args>()...))) \
: values(std::forward<Args>(args)...), index_value(index_value) \
{ \
VULKAN_CPU_UTIL_VARIANT_BASE4(true)
template <typename T>
-struct variant_is_in_place_index
+struct Variant_is_in_place_index
{
static constexpr bool value = false;
};
template <std::size_t I>
-struct variant_is_in_place_index<in_place_index_t<I>>
+struct Variant_is_in_place_index<in_place_index_t<I>>
{
static constexpr bool value = true;
};
template <typename T>
-struct variant_is_in_place_type
+struct Variant_is_in_place_type
{
static constexpr bool value = false;
};
template <typename T>
-struct variant_is_in_place_type<in_place_type_t<T>>
+struct Variant_is_in_place_type<in_place_type_t<T>>
{
static constexpr bool value = true;
};
variant_dispatch(Fn &&fn, const variant<Types...> &&v, Args &&... args);
template <typename... Types>
-using variant_base_t = variant_base<detail::variant_is_trivially_destructible<Types...>(),
- detail::variant_values<Types...>::is_copy_constructible,
- detail::variant_values<Types...>::is_move_constructible,
- detail::variant_values<Types...>::is_copy_assignable,
- detail::variant_values<Types...>::is_move_assignable,
+using Variant_base_t = Variant_base<variant_is_trivially_destructible<Types...>(),
+ Variant_values<Types...>::is_copy_constructible,
+ Variant_values<Types...>::is_move_constructible,
+ Variant_values<Types...>::is_copy_assignable,
+ Variant_values<Types...>::is_move_assignable,
Types...>;
}
template <typename... Types>
-class variant : private detail::variant_base_t<Types...>
+class variant : private detail::Variant_base_t<Types...>
{
static_assert(sizeof...(Types) > 0, "empty variant is not permitted");
private:
- typedef typename detail::variant_values<Types...>::type_0 type_0;
- typedef detail::variant_base_t<Types...> base;
+ typedef typename detail::Variant_values<Types...>::Type_0 Type_0;
+ typedef detail::Variant_base_t<Types...> Base;
private:
- using base::values;
- using base::index_value;
+ using Base::values;
+ using Base::index_value;
public:
template <bool extra_condition = true,
typename = typename std::
- enable_if<extra_condition && std::is_default_constructible<type_0>::value>::type>
- constexpr variant() noexcept(std::is_nothrow_default_constructible<type_0>::value)
- : base(detail::variant_base_construct_tag{}, 0)
+ enable_if<extra_condition && std::is_default_constructible<Type_0>::value>::type>
+ constexpr variant() noexcept(std::is_nothrow_default_constructible<Type_0>::value)
+ : Base(detail::Variant_base_construct_tag{}, 0)
{
}
template <
typename T,
typename Deduced_Type = typename decltype(
- detail::variant_hypothetical_overload_set<Types...>::fn(std::declval<T>()))::type,
+ detail::Variant_hypothetical_overload_set<Types...>::fn(std::declval<T>()))::type,
std::size_t Index =
- detail::variant_values<Types...>::template index_from_type<Deduced_Type>(),
+ detail::Variant_values<Types...>::template index_from_type<Deduced_Type>(),
typename = typename std::
enable_if<(Index < sizeof...(Types))
&& !std::is_same<typename std::decay<T>::type, variant>::value
- && !detail::variant_is_in_place_index<typename std::decay<T>::type>::value
- && !detail::variant_is_in_place_type<typename std::decay<T>::type>::value
+ && !detail::Variant_is_in_place_index<typename std::decay<T>::type>::value
+ && !detail::Variant_is_in_place_type<typename std::decay<T>::type>::value
&& std::is_constructible<variant_alternative_t<Index, variant<Types...>>,
T>::value>::type>
constexpr variant(T &&value) noexcept(
std::is_nothrow_constructible<variant_alternative_t<Index, variant<Types...>>, T>::value)
- : base(detail::variant_base_construct_tag{},
+ : Base(detail::Variant_base_construct_tag{},
Index,
in_place_index<Index>,
std::forward<T>(value))
}
template <typename T,
typename... Args,
- std::size_t Index = detail::variant_values<Types...>::template index_from_type<T>(),
+ std::size_t Index = detail::Variant_values<Types...>::template index_from_type<T>(),
typename = typename std::enable_if<(Index < sizeof...(Types))
&& std::is_constructible<T, Args...>::value>::type>
constexpr explicit variant(in_place_type_t<T>, Args &&... args) noexcept(
std::is_nothrow_constructible<T, Args...>::value)
- : base(detail::variant_base_construct_tag{},
+ : Base(detail::Variant_base_construct_tag{},
Index,
in_place_index<Index>,
std::forward<Args>(args)...)
typename T,
typename U,
typename... Args,
- std::size_t Index = detail::variant_values<Types...>::template index_from_type<T>(),
+ std::size_t Index = detail::Variant_values<Types...>::template index_from_type<T>(),
typename = typename std::
enable_if<(Index < sizeof...(Types))
&& std::is_constructible<T, std::initializer_list<U>, Args...>::value>::type>
Args &&... args) noexcept(std::is_nothrow_constructible<T,
std::initializer_list<U>,
Args...>::value)
- : base(detail::variant_base_construct_tag{},
+ : Base(detail::Variant_base_construct_tag{},
Index,
in_place_index<Index>,
il,
constexpr explicit variant(in_place_index_t<Index>, Args &&... args) noexcept(
std::is_nothrow_constructible<variant_alternative_t<Index, variant<Types...>>,
Args...>::value)
- : base(detail::variant_base_construct_tag{},
+ : Base(detail::Variant_base_construct_tag{},
Index,
in_place_index<Index>,
std::forward<Args>(args)...)
noexcept(std::is_nothrow_constructible<variant_alternative_t<Index, variant<Types...>>,
std::initializer_list<U>,
Args...>::value)
- : base(detail::variant_base_construct_tag{},
+ : Base(detail::Variant_base_construct_tag{},
Index,
in_place_index<Index>,
il,
template <
typename T,
typename Deduced_Type = typename decltype(
- detail::variant_hypothetical_overload_set<Types...>::fn(std::declval<T>()))::type,
+ detail::Variant_hypothetical_overload_set<Types...>::fn(std::declval<T>()))::type,
std::size_t Index =
- detail::variant_values<Types...>::template index_from_type<Deduced_Type>(),
+ detail::Variant_values<Types...>::template index_from_type<Deduced_Type>(),
typename = typename std::
enable_if<(Index < sizeof...(Types))
&& !std::is_same<typename std::decay<T>::type, variant>::value
- && !detail::variant_is_in_place_index<typename std::decay<T>::type>::value
- && !detail::variant_is_in_place_type<typename std::decay<T>::type>::value
+ && !detail::Variant_is_in_place_index<typename std::decay<T>::type>::value
+ && !detail::Variant_is_in_place_type<typename std::decay<T>::type>::value
&& std::is_constructible<variant_alternative_t<Index, variant<Types...>>,
T>::value
&& std::is_assignable<variant_alternative_t<Index, variant<Types...>>,
{
if(index_value.get() == Index)
{
- detail::variant_get<Index, Types...>::get(values) = std::forward<T>(new_value);
+ detail::Variant_get<Index, Types...>::get(values) = std::forward<T>(new_value);
}
else
{
values.destruct(index_value.get());
index_value.set(variant_npos); // in case construction throws
- auto &value = detail::variant_get<Index, Types...>::get(values);
+ auto &value = detail::Variant_get<Index, Types...>::get(values);
new(const_cast<void *>(static_cast<const volatile void *>(std::addressof(value))))
variant_alternative_t<Index, variant<Types...>>(std::forward<T>(new_value));
index_value.set(Index);
}
template <typename T,
typename... Args,
- std::size_t Index = detail::variant_values<Types...>::template index_from_type<T>(),
+ std::size_t Index = detail::Variant_values<Types...>::template index_from_type<T>(),
typename = typename std::enable_if<(Index < sizeof...(Types))
&& std::is_constructible<T, Args...>::value>::type>
void emplace(Args &&... args)
typename T,
typename U,
typename... Args,
- std::size_t Index = detail::variant_values<Types...>::template index_from_type<T>(),
+ std::size_t Index = detail::Variant_values<Types...>::template index_from_type<T>(),
typename = typename std::
enable_if<(Index < sizeof...(Types))
&& std::is_constructible<T, std::initializer_list<U>, Args...>::value>::type>
{
values.destruct(index_value.get());
index_value.set(variant_npos); // in case construction throws
- auto &value = detail::variant_get<Index, Types...>::get(values);
+ auto &value = detail::Variant_get<Index, Types...>::get(values);
new(const_cast<void *>(static_cast<const volatile void *>(std::addressof(value))))
variant_alternative_t<Index, variant<Types...>>(std::forward<Args>(args)...);
index_value.set(Index);
{
values.destruct(index_value.get());
index_value.set(variant_npos); // in case construction throws
- auto &value = detail::variant_get<Index, Types...>::get(values);
+ auto &value = detail::Variant_get<Index, Types...>::get(values);
new(const_cast<void *>(static_cast<const volatile void *>(std::addressof(value))))
variant_alternative_t<Index, variant<Types...>>(il, std::forward<Args>(args)...);
index_value.set(Index);
template <bool extra_condition = true,
typename =
typename std::enable_if<extra_condition
- && detail::variant_values<Types...>::is_swappable>::type>
- void swap(variant &rt) noexcept(detail::variant_values<Types...>::is_nothrow_swappable)
+ && detail::Variant_values<Types...>::is_swappable>::type>
+ void swap(variant &rt) noexcept(detail::Variant_values<Types...>::is_nothrow_swappable)
{
if(index_value.get() == rt.index_value.get())
values.swap(rt.values, index_value.get());
const variant<Types2...> &v);
template <typename... Types2>
friend constexpr
- typename std::enable_if<detail::variant_values<Types2...>::is_equals_comparable, bool>::type
+ typename std::enable_if<detail::Variant_values<Types2...>::is_equals_comparable, bool>::type
operator==(const variant<Types2...> &l, const variant<Types2...> &r) noexcept(
- detail::variant_values<Types2...>::is_nothrow_equals_comparable);
+ detail::Variant_values<Types2...>::is_nothrow_equals_comparable);
template <typename... Types2>
friend constexpr
- typename std::enable_if<detail::variant_values<Types2...>::is_less_comparable, bool>::type
+ typename std::enable_if<detail::Variant_values<Types2...>::is_less_comparable, bool>::type
operator<(const variant<Types2...> &l, const variant<Types2...> &r) noexcept(
- detail::variant_values<Types2...>::is_nothrow_less_comparable);
+ detail::Variant_values<Types2...>::is_nothrow_less_comparable);
template <typename Fn, typename... Types2, typename... Args>
friend
typename std::common_type<decltype(std::declval<Fn>()(std::declval<Types2 &>()))...>::type
template <typename T, typename... Types>
constexpr bool holds_alternative(const variant<Types...> &v) noexcept
{
- constexpr std::size_t index = detail::variant_values<Types...>::template index_from_type<T>();
+ constexpr std::size_t index = detail::Variant_values<Types...>::template index_from_type<T>();
static_assert(index != variant_npos, "");
return v.index_value.get() == index;
}
{
static_assert(Index < sizeof...(Types), "");
if(v.index_value.get() == Index)
- return detail::variant_get<Index, Types...>::get(v.values);
+ return detail::Variant_get<Index, Types...>::get(v.values);
throw bad_variant_access();
}
{
static_assert(Index < sizeof...(Types), "");
if(v.index_value.get() == Index)
- return detail::variant_get<Index, Types...>::get(v.values);
+ return detail::Variant_get<Index, Types...>::get(v.values);
throw bad_variant_access();
}
template <typename T, typename... Types>
constexpr const T &get(const variant<Types...> &v)
{
- return get<detail::variant_values<Types...>::template index_from_type<T>()>(v);
+ return get<detail::Variant_values<Types...>::template index_from_type<T>()>(v);
}
template <typename T, typename... Types>
constexpr T &get(variant<Types...> &v)
{
- return get<detail::variant_values<Types...>::template index_from_type<T>()>(v);
+ return get<detail::Variant_values<Types...>::template index_from_type<T>()>(v);
}
template <typename T, typename... Types>
constexpr const T &&get(const variant<Types...> &&v)
{
- return get<detail::variant_values<Types...>::template index_from_type<T>()>(std::move(v));
+ return get<detail::Variant_values<Types...>::template index_from_type<T>()>(std::move(v));
}
template <typename T, typename... Types>
constexpr T &&get(variant<Types...> &&v)
{
- return get<detail::variant_values<Types...>::template index_from_type<T>()>(std::move(v));
+ return get<detail::Variant_values<Types...>::template index_from_type<T>()>(std::move(v));
}
template <std::size_t Index, typename... Types>
template <typename T, typename... Types>
constexpr const T *get_if(const variant<Types...> *v) noexcept
{
- return get_if<detail::variant_values<Types...>::template index_from_type<T>()>(v);
+ return get_if<detail::Variant_values<Types...>::template index_from_type<T>()>(v);
}
template <typename T, typename... Types>
constexpr T *get_if(variant<Types...> *v) noexcept
{
- return get_if<detail::variant_values<Types...>::template index_from_type<T>()>(v);
+ return get_if<detail::Variant_values<Types...>::template index_from_type<T>()>(v);
}
template <typename... Types>
constexpr
- typename std::enable_if<detail::variant_values<Types...>::is_equals_comparable, bool>::type
+ typename std::enable_if<detail::Variant_values<Types...>::is_equals_comparable, bool>::type
operator==(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_equals_comparable)
+ detail::Variant_values<Types...>::is_nothrow_equals_comparable)
{
return l.index_value.get() == r.index_value.get()
&& l.values.is_equal(r.values, l.index_value.get());
template <typename... Types>
constexpr
- typename std::enable_if<detail::variant_values<Types...>::is_equals_comparable, bool>::type
+ typename std::enable_if<detail::Variant_values<Types...>::is_equals_comparable, bool>::type
operator!=(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_equals_comparable)
+ detail::Variant_values<Types...>::is_nothrow_equals_comparable)
{
return !operator==(l, r);
}
template <typename... Types>
-constexpr typename std::enable_if<detail::variant_values<Types...>::is_less_comparable, bool>::type
+constexpr typename std::enable_if<detail::Variant_values<Types...>::is_less_comparable, bool>::type
operator<(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_less_comparable)
+ detail::Variant_values<Types...>::is_nothrow_less_comparable)
{
if(l.index_value.get() != r.index_value.get())
return l.index_value.get() < r.index_value.get();
}
template <typename... Types>
-constexpr typename std::enable_if<detail::variant_values<Types...>::is_less_comparable, bool>::type
+constexpr typename std::enable_if<detail::Variant_values<Types...>::is_less_comparable, bool>::type
operator>(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_less_comparable)
+ detail::Variant_values<Types...>::is_nothrow_less_comparable)
{
return operator<(r, l);
}
template <typename... Types>
-constexpr typename std::enable_if<detail::variant_values<Types...>::is_less_comparable, bool>::type
+constexpr typename std::enable_if<detail::Variant_values<Types...>::is_less_comparable, bool>::type
operator>=(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_less_comparable)
+ detail::Variant_values<Types...>::is_nothrow_less_comparable)
{
return !operator<(l, r);
}
template <typename... Types>
-constexpr typename std::enable_if<detail::variant_values<Types...>::is_less_comparable, bool>::type
+constexpr typename std::enable_if<detail::Variant_values<Types...>::is_less_comparable, bool>::type
operator<=(const variant<Types...> &l, const variant<Types...> &r) noexcept(
- detail::variant_values<Types...>::is_nothrow_less_comparable)
+ detail::Variant_values<Types...>::is_nothrow_less_comparable)
{
return !operator<(r, l);
}
template <typename... Types,
typename = typename std::
- enable_if<vulkan_cpu::util::detail::variant_values<Types...>::is_swappable>::type>
+ enable_if<vulkan_cpu::util::detail::Variant_values<Types...>::is_swappable>::type>
inline void
swap(vulkan_cpu::util::variant<Types...> &l, vulkan_cpu::util::variant<Types...> &r) noexcept(
- vulkan_cpu::util::detail::variant_values<Types...>::is_nothrow_swappable)
+ vulkan_cpu::util::detail::Variant_values<Types...>::is_nothrow_swappable)
{
l.swap(r);
}
namespace detail
{
template <typename... Types>
-struct void_t_helper
+struct Void_t_helper
{
typedef void type;
};
}
template <typename... Types>
-using void_t = typename detail::void_t_helper<Types...>::type;
+using void_t = typename detail::Void_t_helper<Types...>::type;
}
}