2016-03-04 77 views
0

我想在R包內編譯C++ 11下的sitmo prngThe problematic code has been packaged and is available here.此R包的目標是提供sitmo header file以便其他包能夠使用說明中的LinkTo字段。作爲額外的獎勵,該軟件包計劃隨附Armadillo + OpenMP示例。還有一個包,mvnfast,它使用sitmo,但只在C++ 98和boost頭文件中。編譯問題與sitmo prng,c + + 11和犰狳

我認爲我收到的錯誤是特定於OS Xclang。我無法通過win-build在Windows上覆制它。這就是說,錯誤是:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3641:44: error: non-type template argument is not a constant expression 
     const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; 

錯誤只是彈出在Rcpp dev list。這種情況下的解決方案是在C++ 98下編譯並使用boost。

後跟上述錯誤由下列說明:

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3773:18: note: in instantiation of function template specialization 'std::__1::generate_canonical<double, 53, sitmo::prng_engine>' requested here 
     * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) 
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3737:17: note: in instantiation of function template specialization 'std::__1::uniform_real_distribution<double>::operator()<sitmo::prng_engine>' requested here 
     {return (*this)(__g, __p_);} 
       ^
sitmo_test.cpp:77:26: note: in instantiation of function template specialization 'std::__1::uniform_real_distribution<double>::operator()<sitmo::prng_engine>' requested here 
     double u = distunif(engine); 
         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3641:44: note: non-constexpr function 'max' cannot be used in a constant expression 
    const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; 
             ^
../inst/include/prng_engine.hpp:100:23: note: declared here 
    static result_type (max)() { return 0xFFFFFFFF; } 

正在使用的版本是:

Apple LLVM version 7.0.2 (clang-700.1.81) 
Target: x86_64-apple-darwin15.3.0 
Thread model: posix 
+0

你好。我會試着去看一看,但不要今晚。我也有sitmo的東西看看...你也可以把它帶到rcpp-devel嗎? –

+0

當然,我也會將問題發佈到rcpp-devel。 – coatless

+0

@DirkEddelbuettel我懷疑sitmo在這裏是不對的,請看看 –

回答

2

尋找到代碼,有一個錯誤在sitmo prng_engine.h。 min()max()被宣佈爲

static result_type (min)() { return 0; } 

static result_type (max)() { return 0xFFFFFFFF; } 

如果你從here看看,比如說,標準LCG max,你可以看到它正在宣佈constexpr,同上,用於min

只要你在sitmo頭文件中創建了這些方法constexpr,我相信你可以在模板表達式中使用它們。

UPDATE

我已經研究過GCC 5頭,方法確實被宣佈constexpr

+0

精美的作品!感謝您接收此信息。 – coatless

+2

@ Coatless不用客氣。你打算向sitmo傢伙提交報告嗎? –

+1

已發送電子郵件。 =) – coatless