Skip to content

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

Description

@jschueller

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 >>'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions