https://mooseframework.inl.gov
StreamArguments.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include <tuple>
13 #include <sstream>
14 #include <string>
15 
16 /***
17  * Streams all of the given arguments into the given stream
18  */
19 template <class StreamType>
20 void
21 streamArguments(StreamType &)
22 {
23 }
24 
25 // Recursive parameter pack expansion
26 template <class StreamType, typename T, typename... Args>
27 void
28 streamArguments(StreamType & ss, T && val, Args &&... args)
29 {
30  ss << val;
31  streamArguments(ss, std::forward<Args>(args)...);
32 }
33 
34 // Base case for Tuple expansion recursive method
35 template <std::size_t I = 0, class StreamType, typename... Args>
36 inline typename std::enable_if<I == sizeof...(Args), void>::type
37 streamArguments(StreamType & /*ss*/, std::tuple<Args...> /*args*/)
38 {
39 }
40 
41 // Recursive method for tuple expansion
42 // clang-format off
43 template <std::size_t I = 0, class StreamType, typename... Args>
44 inline typename std::enable_if<I < sizeof...(Args), void>::type
45 streamArguments(StreamType & ss, std::tuple<Args...> args)
46 {
47  ss << std::get<I>(args);
48  streamArguments<I + 1, StreamType, Args...>(ss, args);
49 }
50 
51 /***
52  * Streams all of the given arguments into a string
53  */
54 template <typename... Args>
55 std::string
56 argumentsToString(Args &&... args)
57 {
58  std::ostringstream ss;
59  streamArguments(ss, std::forward<Args>(args)...);
60  return ss.str();
61 }
62 
63 // clang-format on
void streamArguments(StreamType &)