#include <string>
#include <map>
#include <type_traits>
using from_type = std::map<std::string, std::string>;
template<typename PK, size_t N>
struct pf {
pf(from_type const& a, std::string const& pkn) noexcept(noexcept(fill(pk_, std::string{})))
: map_(a) // GCC 4.8 requires ()s for references
, pk_{ [&]{ fill(pk_, pkn); return pk_; }() }
{
}
template<typename prop_t>
typename std::enable_if<
std::is_integral<typename std::decay<prop_t>::type>::value,
pf<PK, N>>::type const&
fill(prop_t& , std::string const& , prop_t = 0) const noexcept(false);
pf<PK, N> const&
fill(std::string& , std::string const&) const noexcept;
protected:
from_type const& map_;
public:
PK pk_;
};
$ clang++ -std=c++14 -Wall -pedantic -Wextra pf.cpp
$ g++ -std=c++1y -Wall -pedantic -Wextra pf.cpp
pf.cpp:10:75: error: ‘pk_’ was not declared in this scope; did you mean ‘pkn’?
10 | pf(from_type const& a, std::string const& pkn) noexcept(noexcept(fill(pk_, std::string{})))
| ^~~
| pkn
成功编译:
编译失败:
如果我将pk_
的声明移到类的开头,那么GCC也会对其进行编译。
哪个编译器系列正确?