template<typename SystemContext SystemContext, typename Element>
gtopt::ElementTraits struct

Defines default traits for element access and manipulation.

Template parameters
SystemContext The context providing access to the system model.
Element The type of element these traits are for.

This traits struct provides a generic implementation for interacting with elements within a SystemContext. It forwards calls to the underlying SystemLP object.

Public static functions

template<template<typename> class Id>
static auto get_element(SystemContext& sc, const Id<Element>& id) -> auto&&
Gets a reference to an element by its ID.
template<template<typename> class Id>
static auto get_element_index(SystemContext& sc, const Id<Element>& id) -> auto
Gets the index of an element by its ID.
static auto get_elements(SystemContext& sc) -> auto&&
Gets a container of all elements of a specific type.
template<typename ElementType2>
static auto push_back(SystemContext& sc, ElementType2&& e) -> auto
Adds a new element to the system.

Function documentation

template<typename SystemContext SystemContext, typename Element> template<template<typename> class Id>
static auto&& gtopt::ElementTraits<SystemContext, Element>::get_element(SystemContext& sc, const Id<Element>& id)

Gets a reference to an element by its ID.

Parameters
sc The system context.
id The ID of the element.
Returns A reference to the element.

Routes through sc.get_element(id) — a fully-inline template in system_context.hpp using void* dispatch — so that call sites do NOT need to include system_lp.hpp to instantiate this template.

template<typename SystemContext SystemContext, typename Element> template<template<typename> class Id>
static auto gtopt::ElementTraits<SystemContext, Element>::get_element_index(SystemContext& sc, const Id<Element>& id)

Gets the index of an element by its ID.

Parameters
sc The system context.
id The ID of the element.
Returns The ElementIndex for the given ID.

template<typename SystemContext SystemContext, typename Element>
static auto&& gtopt::ElementTraits<SystemContext, Element>::get_elements(SystemContext& sc)

Gets a container of all elements of a specific type.

Parameters
sc The system context.
Returns A reference to the container of elements.
Exceptions
std::runtime_error — propagates from SystemLP::elements<X>(). See its docstring for the low_memory contract.

template<typename SystemContext SystemContext, typename Element> template<typename ElementType2>
static auto gtopt::ElementTraits<SystemContext, Element>::push_back(SystemContext& sc, ElementType2&& e)

Adds a new element to the system.

Parameters
sc The system context.
e The element to add.
Returns The ElementIndex of the newly added element.