I have found questions that are almost exactly as mine but I have 1 extra requirement - I need something that I can use as a default argument.
I'm writing a header only template library and I have a code like this:
#include <chrono>
template <typename T>
class Foo
{
public:
using Duration = std::chrono::duration<float>;
static constexpr Duration DefaultDuration{1.0f};
Foo(Duration duration = DefaultDuration)
: duration{duration}
{
}
private:
Duration duration;
};
int main(int argc, char* argv[])
{
Foo<int> foo;
}
As you can see, I can't use a function call because it wouldn't work as a default argument, right? Is there a solution?