From f144e878b2c128b29fe4e8841d632939456b93fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 10 Feb 2018 08:28:09 +0100 Subject: [PATCH] Add vector fallback for get/set! --- src/attributes.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/attributes.jl b/src/attributes.jl index c48a850dc0..4b02643084 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -110,6 +110,10 @@ get(instance, ConstraintIndex, "con1") ``` """ function get end +# We want to avoid being too specific in the type arguments to avoid method ambiguity. +# For instance, get(::AbstractInstance, ::AbstractVariableAttribute, ::Vector{VariableIndex}) would not allow +# to define get(::SomeInstance, ::AnyProperty, ::Vector) +get(instance::AbstractInstance, attr::AnyProperty, idxs::Vector) = get.(instance, attr, idxs) _name(attr::AnyAttribute) = "attribute $attr" _name(attr::AbstractSolverParameter) = "parameter $attr" @@ -229,6 +233,9 @@ Assign a value to the attribute `attr` of constraint `c` in instance `instance`. Assign a value respectively to the attribute `attr` of each constraint in the collection `c` in instance `instance`. """ function set! end +# See note with get +set!(instance::AbstractInstance, attr::AnyProperty, idxs::Vector, vector_of_values::Vector) = set!.(instance, attr, idxs, vector_of_values) + function set!(instance::AbstractInstance, attr::AnyProperty, args...) throw(ArgumentError("AbstractInstance of type $(typeof(instance)) does not support setting the $(_name(attr))")) end