[WIP] Add cetl::variant - #92
Conversation
…because I am going to need that for the variant #verification #docs #sonar
…alueless_by_exception; now we need to slightly adjust the internals before moving further to eliminate certain redundancies
…RAM to compile, let's see how it goes #verification #docs #sonar
…he CI has run out of memory #verification #docs #sonar
ea64dd6 to
73b54a8
Compare
…5566/1007777; re-enable after upgrading to Doxygen v1.10
…memory limits; add a simple constexpr test
46ab9e1 to
6403161
Compare
|
Well, the pull request is finished, except that the CI is still misbehaving. I have already split the tests into six translation units to manage the memory consumption by the compiler. I can split it further if needed but I am not yet confident that this is going to help. The new error from the CI is this:
According to this, it may happen due to high CPU/memory utilization: actions/runner-images#7897 |
To reduce memory footprint of the compiler
|
@thirtytwobits I would like to add an exception for the coverage requirement for variant.hpp because currently it is computed per template instantiation, and the test suite is built to test a small fraction of branches per instantiation, which leads to a very low coverage estimate. I'm not sure if it warrants an extension of the coverage exclusion list: CETL/.github/workflows/cetlvast.yml Line 158 in f58f00f |
thirtytwobits
left a comment
There was a problem hiding this comment.
Approved but could you add this example first:
cetlvast/suites/docs/examples/example_09_variant.cpp
/// @file
/// Example of using cetl::variant.
///
/// @copyright
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// Copyright Amazon.com Inc. or its affiliates.
/// SPDX-License-Identifier: MIT
///
#include "cetl/pf17/variant.hpp"
#include <string>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <gtest/gtest.h>
TEST(example_09_variant, basic_usage)
{
//! [example_09_basic_usage]
/// This example is taken directly from the [cppreference.com](https://en.cppreference.com/w/cpp/utility/variant)
/// documentation.
cetl::pf17::variant<int, float> v, w;
v = 42; // v contains int
int i = cetl::pf17::get<int>(v);
assert(42 == i); // succeeds
w = cetl::pf17::get<int>(v);
w = cetl::pf17::get<0>(v); // same effect as the previous line
w = v; // same effect as the previous line
// cetl::pf17::get<double>(v); // error: no double in [int, float]
// cetl::pf17::get<3>(v); // error: valid index values are 0 and 1
float* result = cetl::pf17::get_if<float>(&w); // w contains int, not float: will return null
std::cout << "get_if<float>(&w) => " << result << '\n';
using namespace std::literals;
cetl::pf17::variant<std::string> x("abc");
// converting constructors work when unambiguous
x = "def"; // converting assignment also works when unambiguous
cetl::pf17::variant<std::string, void const*> y("abc");
// casts to void const * when passed a char const *
assert(cetl::pf17::holds_alternative<void const*>(y)); // succeeds
y = "xyz"s;
assert(cetl::pf17::holds_alternative<std::string>(y)); // succeeds
//! [example_09_basic_usage]
}
|



This is just an ordinary variant, nothing special here.
Other changes:
conjunction_vetc.overloadedhelper class, which is not found in the standard library but is commonly used with visitation. We can move it somewhere if its current place is found unsuitable.type_traits_ext.hppwith type traits intended for internal use mostly.detailnamespace.WARN_AS_ERRORbecause Doxygen v1.9 is unable to parse certain recursive templates correctly; see https://stackoverflow.com/a/77855566/1007777