At the end of this post is my code.
I’m working on emulating something similar to Concepts using the detector idiom proposed for standardization in Library Fundamentals 2 TS. Unfortunately, NVCC refuses to correctly compile the code when it’s within a CU file. When it’s a standard CPP file it gets compiled by the host compiler and all is good.
I have verified that this example compiles under:
gcc++ 4.7 and newer
clang++ 3.4 and newer
icpc 13.0 and newer
pgi 15.4 and newer
But somehow it still fails with NVCC.
I’m using CUDA 8.0 currently (v8.0.61)
the exact command it fails with is the first pass of the cuda frontend compiler (cudafe)
cudafe --allow_managed --m64 --gnu_version=40903 --c++11 -tused --no_remove_unneeded_entities --gen_c_file_name “mwe.cudafe1.c” --stub_file_name “mwe.cudafe1.stub.c” --gen_device_file_name “mwe.cudafe1.gpu” --nv_arch “compute_20” --gen_module_id_file --module_id_file_name “mwe.module_id” --include_file_name “mwe.fatbin.c” “mwe.cpp1.ii”
==============================
// compiled with:
//
// nvcc -std=c++11 <filename.cu>
// TMP bool types
template <typename T, T Val>
struct integral_constant {
using type = T;
static constexpr T value = Val;
};
template <bool B>
using bool_ = integral_constant<bool, B>;
using true_type = bool_<true>;
using false_type = bool_<false>;
// detector idiom
template <class...>
struct voider {
using type = void;
};
template <class... T>
using void_t = typename voider<T...>::type;
template <class, template <class...> class Op, class... Args>
struct detector {
using value_t = false_type;
};
template <template <class...> class Op, class... Args>
struct detector<void_t<Op<Args...>>, Op, Args...> {
using value_t = true_type;
using type = int;
};
// concepts
template <typename T>
T&& declval() noexcept;
template <typename T>
using IsAType = decltype(declval<T>());
// user code
int main()
{
static_assert(detector<void, IsAType, int>::value_t::value,
"int is somehow not a type");
// this static_assert somehow fails but should NOT fail
}