gem5  v21.1.0.2
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 
59 template <typename T>
60 std::enable_if_t<IsHelpedContainer<T>::value, std::ostream &>
61 operator<<(std::ostream& out, const T &t)
62 {
63  out << "[ ";
64  bool first = true;
65  auto printer = [&first, &out](const auto &elem) {
66  if (first)
67  out << elem;
68  else
69  out << " " << elem;
70  };
71  std::for_each(t.begin(), t.end(), printer);
72  out << " ]";
73  out << std::flush;
74  return out;
75 }
76 
77 } // namespace stl_helpers
78 } // namespace gem5
79 
80 #endif // __BASE_STL_HELPERS_HH__
gem5::X86ISA::vector
Bitfield< 15, 8 > vector
Definition: intmessage.hh:48
GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(m5, gem5)
compiler.hh
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
gem5::stl_helpers::IsHelpedContainer
Definition: stl_helpers.hh:47
std
Overload hash function for BasicBlockRange type.
Definition: types.hh:111
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::stl_helpers::operator<<
std::enable_if_t< IsHelpedContainer< T >::value, 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:61

Generated on Tue Sep 21 2021 12:25:00 for gem5 by doxygen 1.8.17