考虑以下在Clang 3.8上成功编译的问题-std=c++14
.
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
constexpr bool test = (i == (j == i ? j : i));
static_assert(test, "error");
});
});
}
Run Code Online (Sandbox Code Playgroud)
测试是非常不敏感的,但这不是重点.现在考虑一个替代版本,其中测试直接放在static_assert
:
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
static_assert((i == (j == i ? j …
Run Code Online (Sandbox Code Playgroud)