14#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_DERIVED_DATA_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_DERIVED_DATA_H_
22#include "absl/log/log.h"
23#include "absl/strings/str_cat.h"
36 std::tuple_size_v<AllAttrTypeDescriptors>;
48 template <
typename AttrT>
54 std::is_const_v<std::conditional_t<(index >= 0),
const AttrT, AttrT>>,
62 template <
typename Fn>
65 [&fn](
const auto& descriptor) {
66 for (
auto attr : descriptor.Enumerate()) {
75template <
typename AttrT>
93template <
typename AttrType>
103template <
typename AttrType>
108template <
typename AttrType>
115template <
typename AttrType>
117 const AttrType attr) {
128template <
template <
int i>
typename ValueType>
132 return std::make_tuple(ValueType<i>()...);
137template <
int n,
template <
int i>
typename ValueType>
146template <
template <
int i>
typename ValueType>
149 template <
typename AttrT>
150 ValueType<AllAttrs::GetIndex<AttrT>()>&
operator[](AttrT a) {
152 return std::get<AllAttrs::GetIndex<AttrT>()>(
153 array_tuple_)[
static_cast<int>(a)];
156 template <
typename AttrT>
157 const ValueType<AllAttrs::GetIndex<AttrT>()>&
operator[](AttrT a)
const {
160 return (*
const_cast<AttrMap*
>(
this))[a];
167 template <
typename Fn>
171 for (
auto& value : array) {
186template <
typename AttrType,
typename Fn,
int n = 0>
189 if constexpr (n < Descriptor::NumAttrs()) {
190 constexpr AttrType a =
static_cast<AttrType
>(n);
192 return fn.template operator()<a>();
196 LOG(FATAL) <<
"impossible";
197 return decltype(fn.template operator()<AttrType{}>()) {};
201template <
typename ValueType>
203 return absl::StrCat(v);
213 return v ?
"true" :
"false";
ValueType< AllAttrs::GetIndex< AttrT >()> & operator[](AttrT a)
void ForEachAttrValue(Fn &&fn)
const ValueType< AllAttrs::GetIndex< AttrT >()> & operator[](AttrT a) const
An object oriented wrapper for quadratic constraints in ModelStorage.
constexpr decltype(auto) ApplyOnIndexRange(Fn &&fn)
AttrKey< AttrTypeDescriptorT< AttrType >::kNumKeyElements, typename AttrTypeDescriptorT< AttrType >::Symmetry > AttrKeyFor
The type of the AttrKey for attribute type AttrType.
decltype(auto) CallForAttr(AttrType attr, Fn &&fn)
Calls fn<attr>().
constexpr int GetAttrKeySize()
constexpr std::array< ElementType, GetAttrKeySize< attr >()> GetElementTypes()
std::tuple< BoolAttr0TypeDescriptor, BoolAttr1TypeDescriptor, IntAttr0TypeDescriptor, IntAttr1TypeDescriptor, DoubleAttr0TypeDescriptor, DoubleAttr1TypeDescriptor, DoubleAttr2TypeDescriptor, SymmetricDoubleAttr2TypeDescriptor, SymmetricDoubleAttr3TypeDescriptor, VariableAttr1TypeDescriptor > AllAttrTypeDescriptors
constexpr decltype(auto) ForEach(Fn &&fn, Tuple &&tuple)
constexpr AttrTypeDescriptorT< decltype(attr)>::ValueType GetAttrDefaultValue()
AllAttrs::TypeDescriptor< AllAttrs::GetIndex< AttrT >()> AttrTypeDescriptorT
Returns the descriptor for attribute AttrT.
typename AttrTypeDescriptorT< AttrType >::ValueType ValueTypeFor
The value type for attribute type AttrType.
static constexpr int GetIndexIfAttr()
std::string FormatAttrValue(const ValueType v)
decltype(ApplyOnIndexRange< n >(EnumeratedTupleCpp17Helper< ValueType >{})) EnumeratedTuple
A tuple of ValueType<i> for i in 0..n.
A helper to manipulate the list of attributes.
std::tuple_element_t< i, AllAttrTypeDescriptors > TypeDescriptor
Returns the descriptor of the i-th attribute type in the list.
static constexpr int kNumAttrTypes
The number of available attribute types.
typename TypeDescriptor< i >::AttrType Type
Returns the i-th attribute type in the list.
static constexpr int GetIndex()
static void ForEachAttr(Fn &&fn)