Closed abeimler closed 4 months ago
Maybe you can write custom glaze wrappers for the fixed_containers
types?
https://github.com/stephenberry/glaze/blob/main/docs/wrappers.md
It isn't actually correct to reflect into the structures inside a FixedVector
for example, because you would "see" the uninitialized slots of the backing array. It's also cleaner to serialize/deserialize into a variable length json array
Maybe you can write custom glaze wrappers for the
fixed_containers
types? https://github.com/stephenberry/glaze/blob/main/docs/wrappers.md
I didn't really need to write an wrapper before the "Implicit Structured Binding"-Update. But I tried .. didn't ready work =/
Concepts are used to allow various containers and even user containers if they match standard library interfaces.
Without the compiler tuple-check, everything works as expected.
It's also cleaner to serialize/deserialize into a variable length json array
yea, I agree but for now I only writing some data out. For now all my data is limited.
EDIT:
I think what happen is, glaze is checking via concept for the type and end up been checking for a tuple:
// Specializations
namespace std
{
template <typename T,
std::size_t MAXIMUM_SIZE,
fixed_containers::customize::SequenceContainerChecking CheckingType>
struct tuple_size<fixed_containers::FixedVector<T, MAXIMUM_SIZE, CheckingType>>
: std::integral_constant<std::size_t, 0>
{
// no value
//static_assert(fixed_containers::AlwaysFalseV<T, decltype(MAXIMUM_SIZE), CheckingType>,
// "Implicit Structured Binding due to the fields being public is disabled");
};
} // namespace std
template <class T>
concept tuple_t = requires(T t) {
std::tuple_size<T>::value;
glz::get<0>(t);
} && !meta_value_t<T> && !range<T>;
Hmm, it is true that glaze shouldn't have to reflect into things that are std::range
s, so it shouldn't need to use a structured binding on it.
Maybe we should not have a static_assert
here so that concepts and SFINAE work properly.
Thanks for reporting!
Firstly, here is the reason why this check even exists:
fixed_containers
have public fields for the sole purpose of making their instances (not types, which work regardless) usable as template parameters (similar to using array instances in templates). The public fields should not be accessed directly and they are named in a way that explicitly expresses this. However, implicit structured binding allows accessing them in a way that doesn't immediately look undesirable, so it should be disabled.
As reported in this thread, the current way of preventing that has the unintended consequence of failing when doing valid metaprogramming, like the one glaze
does to check whether this type is a tuple. However, setting the tuple_size
to 0 is enough to prevent usage of structured bindings - the static_assert
is not necessary.
Removing in https://github.com/teslamotors/fixed-containers/pull/95 for all fixed_containers
.
I verified that glaze
will treat FixedVector
as a range and print only the valid elements after this fix.
Maybe it can be some sort of Warning or enabled via Macro/constexpr for "linting" at compile-time.
#ifdef FC_ENABLE_STRICT_MODE
static inline constexpr auto EnableStrictMode = true;
#else
static inline constexpr auto EnableStrictMode = false;
#endif
static_assert(fixed_containers::EnableStrictMode /*|| fixed_containers::AlwaysFalseV<K, V, CheckingType>*/,
"Implicit Structured Binding due to the fields being public is disabled")
Yeah, could enhance the check like that if need be.
For now, I merged the removal of the static_assert
, so you are unblocked as of 0b2c183b830ea8ebf7ea6a1b3fecc7f8a12536db
.
Hello, I was updating my fork with the newest fixed-containers and got an error, cuz "Implicit Structured Binding due to the fields being public is disabled".
I was not sure what constrain was failing ... I'm using glaze by @stephenberry, seems like glaze is not playing well with fixed-containers.
glaze/core/common.hpp
Error:
https://godbolt.org/z/ns6ns9Kqo
It happens when I try to write an fixed-container (like
EnumMap
orFixedVector
) viaglz::write_json
.Is there a way to "enable" fixed-containers for Serialization ?