![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file provides the StrongVector container that wraps around the STL vector. The wrapper restrict indexing to a pre-specified type-safe integer type or StrongInt (see util/intops/strong_int.h). It prevents accidental indexing by different "logical" integer-like types (e.g. another StrongInt) or native integer types. The wrapper is useful as C++ and the standard template library allows the user to mix "logical" integral indices that might have a different role.
The container can only be indexed by an instance of an StrongInt class, which can be declared as:
where type_name is the desired name for the "logical" integer-like type and the value_type is a supported native integer type such as int or uint64_t (see util/intops/strong_int.h for details).
The wrapper exposes all public methods of STL vector and behaves mostly as pass-through. The only methods modified to ensure type-safety are the operator [] and the at() methods.
EXAMPLES -----------------------------------------------------------------—
NB: Iterator arithmetic bypasses strong typing for the index.
OVERFLOW BEHAVIOR
This class ONLY guards against growing the size beyond the range indexable by the index type in debug mode. In optimized mode the user can CHECK IsValidSize() when deemed important.
Copyright 2025 Francesco Cavaliere Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This design abstracts access to the underlying container, ensuring consistent behavior across the following scenarios:
Namespaces | |
namespace | util |
Classes | |
class | FilterIndexRangeView |
class | IndexFilterView |
class | IndexListView |
struct | NoTransform |
class | StrongVector |
class | TransformView |
class | TwoLevelsView |
struct | TypeCastTransform |
class | ValueFilterView |