#include <exception>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <limits>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include <type_traits>
Go to the source code of this file.
|
| snprintf (message, size+1, p...) |
|
template<class T > |
int | signum (T x) |
| Signum function. More...
|
|
template<class T > |
constexpr T const & | larger_of (T const &a, T const &b) |
| Constant-expression max. More...
|
|
template<class... Params> |
char const * | format (Params...p) |
| printf-like formatting. More...
|
|
template<class T > |
T | string_to (std::string str) |
| Conversion of string to a type. More...
|
|
template<> |
int | string_to (std::string str) |
| Conversion of a string to integer number. More...
|
|
template<> |
double | string_to (std::string str) |
| Conversion of a string to floating-point number. More...
|
|
template<class T > |
T | read_next (std::ifstream &f) |
| Read next entry from input stream. More...
|
|
|
template<typename T > |
T | mmin (T x) |
| Many-argument "min" function. More...
|
|
template<typename T , class... Params> |
T | mmin (T x, Params...p) |
|
|
template<typename T > |
T | mmax (T x) |
| Many-argument "max" function. More...
|
|
template<typename T , class... Params> |
T | mmax (T x, Params...p) |
|
#define declareTypeAsScalar |
( |
|
T | ) |
|
Value:\
{ \
static
const bool value =
true; \
};
static const bool value
Definition: misc.h:126
template<class... Params>
char const* format |
( |
Params... |
p | ) |
|
This function takes an arbitrary number of parameters. It is expected that the first one is the formatting string (printf-like syntax). All the arguments are sent to snprintf without change. This functions returns a pointer to a static character string.
- Note
- The maximal size of the string is hard-coded to 1024 characters.
template<class T >
constexpr T const& larger_of |
( |
T const & |
a, |
|
|
T const & |
b |
|
) |
| |
template<typename T , class... Params>
T mmax |
( |
T |
x, |
|
|
Params... |
p |
|
) |
| |
template<typename T , class... Params>
T mmin |
( |
T |
x, |
|
|
Params... |
p |
|
) |
| |
template<class T >
T read_next |
( |
std::ifstream & |
f | ) |
|
Given an input stream and a template parameter the function "read_next" will scan the stream for the next entry and try to interpret next input as the correct type. The characters between a hash symbol (#) and a newline are ignored (i.e. '#' introduces comments). If the read word is equal to asterisk, the "true" boolean value is trown. If an error occurs, exception is thrown. Otherwise the converted data is returned.
std::ifstream inputfile("input.txt");
double x = read_next<double>(inputfile);
template<class T >
T string_to |
( |
std::string |
str | ) |
|
This is a generic template function that is used to convert a text entry to the specified data type. This generic form is used only if there is no specialization for the given data type. The default action is an error message, then. See the specializations of this function for different types.
template<>
int string_to |
( |
std::string |
str | ) |
|
|
inline |
This function will return an integer value of the text given as argument. The library routine "strtol" is used. If the conversion fails, the function throws an exception.
template<>
double string_to |
( |
std::string |
str | ) |
|
|
inline |
This function will return a floating-point value of the text given as argument. The library routine "strtod" is used. If the conversion fails, the function throws an exception.
message = new char [size + 1] |