Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcg64 stream operator visual studio compilation error C2678: binary '|': no operator found #95

Open
jschueller opened this issue Oct 7, 2024 · 2 comments

Comments

@jschueller
Copy link

using pcg64 stream operator make compilation fail with visual studio 2022 (pcg32 is ok though):

D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31): error C2678: binary '|': no operator found which takes a left-hand operand of type 'pcg_extras::uint_x4<uint32_t,uint64_t>' (or there is no acceptable conversion) [D:\a\pcg-cpp\pcg-cpp\cppref.vcxproj]
  (compiling source file 'sample/cppref-sample.cpp')
      D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
      could be 'built-in C++ operator|(UIntX2, int)'

here is the minimal code to reproduce:

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
#include <cmath>
#include <sstream>

#include "pcg_random.hpp"
 
int main()
{
    // Make a random number engine 
    pcg64 rng(0);

    // save state
    std::stringstream stream;
    stream << rng;
    
    std::cout << "state="<<stream.str()<<std::endl;

    //reload stream
    stream >> rng;
}

here is the complete compiler output:

D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31): error C2678: binary '|': no operator found which takes a left-hand operand of type 'pcg_extras::uint_x4<uint32_t,uint64_t>' (or there is no acceptable conversion) [D:\a\pcg-cpp\pcg-cpp\cppref.vcxproj]
  (compiling source file 'sample/cppref-sample.cpp')
      D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
      could be 'built-in C++ operator|(UIntX2, int)'
          with
          [
              UIntX2=uint64_t
          ]
          D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
          '|': cannot convert argument 1 from 'pcg_extras::uint_x4<uint32_t,uint64_t>' to 'UIntX2'
          with
          [
              UIntX2=uint64_t
          ]
      D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
      or       'built-in C++ operator|(bool, int)'
          D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
          '|': cannot convert argument 1 from 'pcg_extras::uint_x4<uint32_t,uint64_t>' to 'bool'
      D:\a\pcg-cpp\pcg-cpp\include\pcg_uint128.hpp(837,22):
      or       'pcg_extras::uint_x4<UInt,UIntX2> pcg_extras::operator |(const pcg_extras::uint_x4<UInt,UIntX2> &,const pcg_extras::uint_x4<UInt,UIntX2> &)'
          D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
          'pcg_extras::uint_x4<UInt,UIntX2> pcg_extras::operator |(const pcg_extras::uint_x4<UInt,UIntX2> &,const pcg_extras::uint_x4<UInt,UIntX2> &)': could not deduce template argument for 'const pcg_extras::uint_x4<UInt,UIntX2> &' from 'int'
      D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
      while trying to match the argument list '(pcg_extras::uint_x4<uint32_t,uint64_t>, int)'
      D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(336,31):
      the template instantiation context (the oldest one first) is
          D:\a\pcg-cpp\pcg-cpp\sample\cppref-sample.cpp(49,11):
          see reference to class template instantiation 'pcg_detail::engine<uint64_t,pcg_extras::pcg128_t,pcg_detail::xsl_rr_mixin<uint64_t,pcg_extras::pcg128_t>,false,pcg_detail::specific_stream<pcg_extras::pcg128_t>,pcg_detail::default_multiplier<pcg_extras::pcg128_t>>' being compiled
          D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(379,23):
          see reference to class template instantiation 'pcg_detail::specific_stream<pcg_extras::pcg128_t>' being compiled
          D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(334,10):
          while compiling class template member function 'void pcg_detail::specific_stream<pcg_extras::pcg128_t>::set_stream(itype)'
          with
          [
              itype=pcg_extras::pcg128_t
          ]
              D:\a\pcg-cpp\pcg-cpp\include\pcg_random.hpp(624,26):
              see the first reference to 'pcg_detail::specific_stream<pcg_extras::pcg128_t>::set_stream' in 'pcg_detail::operator >>'
@jschueller
Copy link
Author

I just noticed #92 and #88
#92 is the minimum fix for to this issue

@jschueller
Copy link
Author

ping @imneme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant