![]() |
boost::taar::request_attributes — A small type-indexed bag of values attached to one request.
// In header: <boost/taar/core/request_attributes.hpp> class request_attributes { public: // public member functions template<typename T> void set(T); template<typename T> T * find() noexcept; template<typename T> T const * find() const noexcept; template<typename T> bool contains() const noexcept; bool empty() const noexcept; };
Carried by boost::taar::matcher::context::attributes, so whatever an interceptor or a handler::guard check stores is visible to the handler that later runs on the same request, and to argument providers such as handler::attribute_arg<T>(). At most one value is kept per type: storing a second value of the same type replaces the first. Define a dedicated type (struct principal { std::string user; };) rather than storing a bare std::string, so that unrelated code does not collide on the key.
Values must be copy-constructible (they are held in a std::any). An empty bag allocates nothing.
struct principal { std::string user; }; ctx.attributes.set(principal {"alice"}); if (auto const* p = ctx.attributes.find<principal>()) use(p->user);
request_attributes public member functionstemplate<typename T> void set(T value);Store value under its type
T, replacing any value of that type. template<typename T> T * find() noexcept;The stored value of type
T, or nullptr if there is none. template<typename T> T const * find() const noexcept;The stored value of type
T, or nullptr if there is none. template<typename T> bool contains() const noexcept;True if a value of type
T is stored. bool empty() const noexcept;True if no value is stored.