I'd like to pass a list of manipulators to a function, something like this:
void print(const vector<std::smanip>& manips) {
// ...
for (auto m : manips)
cout << m;
// ...
}
which would ideally be called by code something like this:
some_object.print({std::fixed, std::setprecision(2)}));
g++ 4.7.0 says:
error: ‘std::smanip’ has not been declared
Apparently, smanip
isn't really defined in the standard, and C++11 compilers don't need to provide an explicit name for the type of manipulators. I tried declaring a type by leeching off of a known manipulator, like this:
typedef decltype(std::fixed) manip;
This opened up a host of new error messages, including this one:
error: ‘const _Tp* __gnu_cxx::new_allocator< <template-parameter-1-1>
>::address(__gnu_cxx::new_allocator< <template-parameter-1-1> >::const_reference)
const [with _Tp = std::ios_base&(std::ios_base&); __gnu_cxx::new_allocator<
<template-parameter-1-1> >::const_pointer = std::ios_base& (*)(std::ios_base&);
__gnu_cxx::new_allocator< <template-parameter-1-1> >::const_reference =
std::ios_base& (&)(std::ios_base&)]’ cannot be overloaded
Should I just give up now, or is there a way to do this?