veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.05k stars 76 forks source link

refl::util::detail::filter(..) inverts order of member list #64

Closed RalphSteinhagen closed 2 years ago

RalphSteinhagen commented 2 years ago

There might be a regression in the last refl-cpp release: refl::util::detail::filter(..) seems to invert the member order which has a notable impact on the find_first() method.

#include <iostream>
#include <https://raw.githubusercontent.com/veselink1/refl-cpp/master/include/refl.hpp>

struct Point {
    float x;
    float y;
    float z;
};
REFL_TYPE(Point)
    REFL_FIELD(x)
    REFL_FIELD(y)
    REFL_FIELD(z)
REFL_END

constexpr auto members = refl::reflect<Point>().members;
constexpr auto condition = [](auto member) { return true; };
static_assert(find_first(members, condition).name == "x");  // <- fails but should be correct
// static_assert(find_first(members, condition).name == "z"); // works

See compiler-explorer for further details and a live demo of this feature.

veselink1 commented 2 years ago

That's pretty bad! Thanks for reporting!

RalphSteinhagen commented 2 years ago

Fixed by mdrged PR https://github.com/veselink1/refl-cpp/pull/65