template <bool OWNING>
class ampl::BasicVariant

Template class which implements a variant object, with or without ownership semantics.

The object can represent a string or a double number, and maps directly to the underlying AMPL type system. It is not intended to be used directly, please use Variant (with ownership semantics, each object stores the values that it represents) or VariantRef (without ownership semantics, each object is only a reference to values stored elsewhere).

Public Functions

BasicVariant(internal::Variant var)

Default constructor, creates an empty variant.

BasicVariant(int value)
BasicVariant(unsigned value)
BasicVariant(long value)
BasicVariant(unsigned long value)
BasicVariant(double value)

Creates a numeric variant with the specified value.

BasicVariant(const std::string &value)

Creates a string variant which references or owns a copy of the specified string.

BasicVariant(const char *value)

Creates a string variant which references or owns a copy of the specified string literal.

BasicVariant(const BasicVariant &other)

Copy constructor.

If OWNING copy the resources

template <bool U>
BasicVariant(BasicVariant<U> const &other)

Coercing copy constructor.



If OWNING frees the resources.

template <bool U>
BasicVariant &operator=(const BasicVariant<U> &other)

Coercing assignment operator.

BasicVariant &operator=(const BasicVariant &other)

Assignment operator.

const char *c_str() const

Returns the pointer to a C string.

double dbl() const

Returns the numerical value.

std::string str() const

Converts an AMPL variant element to an std::string object.

Type type() const

Returns the type of this variant object.

internal::Variant impl() const
std::string toString() const

Return an AMPL like representation of this variant.

String variants are single-quoted, numeric are not.


typedef BasicVariant<true> ampl::Variant

Public typedef of BasicVariant with ownership semantics.


typedef BasicVariant<false> ampl::VariantRef

Public typedef of BasicVariant without ownership semantics.

It can be used both as a return type when the ownership semantics is not needed (e.g. returning a reference to a value stored in a container) and as an argument type to provide implicit conversions and reduce the number of required overloads.


enum ampl::Type

Represents the type of a value in the AMPL type system, used in the Variant and VariantRef classes.



Empty variant, i.e.

one that does not hold a value


Numeric (floating point) value.


String value.