1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 * This file is open source software, licensed to you under the terms
4 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
5 * distributed with this work for additional information regarding copyright
6 * ownership. You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 * Copyright (C) 2014 Cloudius Systems, Ltd.
23 #ifndef CEPH_ARRAY_MAP_HH_
24 #define CEPH_ARRAY_MAP_HH_
28 // unordered_map implemented as a simple array
30 template <typename Value, size_t Max>
32 std::array<Value, Max> _a {};
34 array_map(std::initializer_list<std::pair<size_t, Value>> i) {
36 _a[kv.first] = kv.second;
39 Value& operator[](size_t key) { return _a[key]; }
40 const Value& operator[](size_t key) const { return _a[key]; }
42 Value& at(size_t key) {
44 throw std::out_of_range(std::to_string(key) + " >= " + std::to_string(Max));
50 #endif /* ARRAY_MAP_HH_ */