c++17 example

I have read an example from the book 《c++17 STL cookbook》.
But I can not compile it under g++8.1 with '-std=c++17'

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <type_traits>

template<class T>
struct sum
{
    T value;
    template<typename ... Ts>
    sum(Ts&& ... values)  -> sum<std::common_type_t<Ts...>> : value{(values + ...)} 
    {}
};

int main()
{}
It looks like you have mixed up the syntax for deduction guides and constructors.

1
2
3
4
5
6
7
8
9
10
template<class T>
struct sum
{
    T value;
    template<typename ... Ts>
    sum(Ts&& ... values) : value{(values + ...)} {} // constructor
};

template <typename ... Ts>
sum(Ts&& ... ts) -> sum<std::common_type_t<Ts...>>;  // deduction guide 
Topic archived. No new replies allowed.