This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "tools/getter_result.hpp"template <typename T, typename U>
struct getter_result {
using type = std::conditional_t<std::is_lvalue_reference_v<T>, const U&, U>;
};
template <typename T, typename U>
using getter_result_t = typename getter_result<T, U>::type;
tools::getter_result is a small type trait that helps you choose an appropriate return type for “getter”-like functions depending on whether the object (this) is an lvalue or an rvalue.
It is especially useful in C++23-style explicit object parameter member functions, e.g.:
auto edges(this auto&& self) -> tools::getter_result_t<decltype(self), std::vector<edge>> {
return std::forward_like<decltype(self)>(self.m_edges);
}
With tools::getter_result, you can write a single getter that:
const U& when called on an lvalue object, andU by value when called on an rvalue object.This allows efficient move (or copy) of the member from temporary objects, while preventing modification through getters on lvalues.
#ifndef TOOLS_GETTER_RESULT_HPP
#define TOOLS_GETTER_RESULT_HPP
#include <type_traits>
namespace tools {
template <typename T, typename U>
struct getter_result {
using type = std::conditional_t<std::is_lvalue_reference_v<T>, const U&, U>;
};
template <typename T, typename U>
using getter_result_t = typename tools::getter_result<T, U>::type;
}
#endif
#line 1 "tools/getter_result.hpp"
#include <type_traits>
namespace tools {
template <typename T, typename U>
struct getter_result {
using type = std::conditional_t<std::is_lvalue_reference_v<T>, const U&, U>;
};
template <typename T, typename U>
using getter_result_t = typename tools::getter_result<T, U>::type;
}