gem5  v22.1.0.0
stl_helpers.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __BASE_STL_HELPERS_HH__
30 #define __BASE_STL_HELPERS_HH__
31 
32 #include <algorithm>
33 #include <iostream>
34 #include <type_traits>
35 #include <vector>
36 
37 #include "base/compiler.hh"
38 
40 namespace gem5
41 {
42 
43 namespace stl_helpers
44 {
45 
46 template <typename T, typename Enabled=void>
47 struct IsHelpedContainer : public std::false_type {};
48 
49 template <typename ...Types>
50 struct IsHelpedContainer<std::vector<Types...>> : public std::true_type {};
51 
52 template <typename ...Types>
53 constexpr bool IsHelpedContainerV = IsHelpedContainer<Types...>::value;
54 
62 template <typename T>
63 std::enable_if_t<IsHelpedContainerV<T>, std::ostream &>
64 operator<<(std::ostream& out, const T &t)
65 {
66  out << "[ ";
67  bool first = true;
68  auto printer = [&first, &out](const auto &elem) {
69  if (first)
70  out << elem;
71  else
72  out << " " << elem;
73  };
74  std::for_each(t.begin(), t.end(), printer);
75  out << " ]";
76  out << std::flush;
77  return out;
78 }
79 
80 } // namespace stl_helpers
81 } // namespace gem5
82 
83 #endif // __BASE_STL_HELPERS_HH__
std::enable_if_t< IsHelpedContainerV< T >, std::ostream & > operator<<(std::ostream &out, const T &t)
Write out all elements in an stl container as a space separated list enclosed in square brackets.
Definition: stl_helpers.hh:64
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 15, 8 > vector
Definition: intmessage.hh:48
constexpr bool IsHelpedContainerV
Definition: stl_helpers.hh:53
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2826
GEM5_DEPRECATED_NAMESPACE(m5, gem5)

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1