#include <array>
#include <cstddef>
#include <iostream>
template <>
struct TypeConverter<std::byte> {
static void fromNative(
UA_Byte src, std::byte& dst) {
dst = std::byte(src);
}
static void toNative(std::byte src,
UA_Byte& dst) {
dst = std::to_integer<UA_Byte>(src);
}
};
}
int main() {
variant.
assign(std::byte{11});
variant = std::byte{11};
std::cout << "Byte value: " << static_cast<int>(valueNative) << std::endl;
const auto value = variant.
to<std::byte>();
std::cout << "Byte value: " << std::to_integer<int>(value) << std::endl;
std::array<std::byte, 3> array{};
variant.
assign(array.begin(), array.end());
std::cout <<
"Array size: " << variant.
arrayLength() << std::endl;
}
View to a contiguous sequence of objects, similar to std::span in C++20.
UA_Variant wrapper class.
T & scalar() &
Get reference to scalar value with given template type (only native or wrapper types).
T to() const
Converts the variant to the specified type T with automatic conversion if required.
size_t arrayLength() const noexcept
Get array length or 0 if variant is not an array.
void assign(std::nullptr_t ptr) noexcept=delete