Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

optional<int> has no == operator to compare with int #2

Open
wlnirvana opened this issue Jan 1, 2023 · 3 comments
Open

optional<int> has no == operator to compare with int #2

wlnirvana opened this issue Jan 1, 2023 · 3 comments

Comments

@wlnirvana
Copy link

Should the following two lines be unwrapped with bit_position.value()?

if (bit_position == 7) {

if (this_.bit_position != 7) {

@falgon
Copy link
Owner

falgon commented Jan 1, 2023

@wlnirvana
It's here.
https://github.com/falgon/SrookCppLibraries/blob/master/srook/optional/core.hpp#L740
Are you getting any errors? If so, please post the compile error message.

@wlnirvana
Copy link
Author

@falgon I was compiling jpezy and got the following error

$ make -j12
[  8%] Creating directories for 'SrookCppLibraries'
[ 16%] Performing download step (git clone) for 'SrookCppLibraries'
-- SrookCppLibraries download command succeeded.  See also /home/benben/projects/jpezy/build/SrookCppLibraries-prefix/src/SrookCppLibraries-stamp/SrookCppLibraries-download-*.log
[ 25%] Performing update step for 'SrookCppLibraries'
[ 33%] No patch step for 'SrookCppLibraries'
[ 41%] No configure step for 'SrookCppLibraries'
[ 50%] No build step for 'SrookCppLibraries'
[ 58%] Performing install step for 'SrookCppLibraries'
-- SrookCppLibraries install command succeeded.  See also /home/benben/projects/jpezy/build/SrookCppLibraries-prefix/src/SrookCppLibraries-stamp/SrookCppLibraries-install-*.log
[ 66%] Completed 'SrookCppLibraries'
[ 66%] Built target SrookCppLibraries
[ 75%] Building CXX object CMakeFiles/jpezy_decode.dir/src/decoder/main.cpp.o
[ 83%] Building CXX object CMakeFiles/jpezy_encode.dir/src/encoder/main.cpp.o
In file included from /home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/bifstream.hpp:5,
                 from /home/benben/projects/jpezy/src/decoder/jpezy_decoder.hpp:20,
                 from /home/benben/projects/jpezy/src/decoder/main.cpp:3:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp: In member function ‘srook::byte* srook::io::jpeg::v1::bifstream::next_address() const’:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:74:26: error: no match for ‘operator==’ (operand types are ‘const srook::optionally::v1::optional<int>’ and ‘int’)
   74 |         if (bit_position == 7) {
      |             ~~~~~~~~~~~~ ^~ ~
      |             |               |
      |             |               int
      |             const srook::optionally::v1::optional<int>
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:74:26: note: candidate: ‘operator==(int, int)’ (built-in)
   74 |         if (bit_position == 7) {
      |             ~~~~~~~~~~~~~^~~~
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:74:26: note:   no known conversion for argument 1 from ‘const srook::optionally::v1::optional<int>’ to ‘int’
In file included from /home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/bifstream.hpp:5,
                 from /home/benben/projects/jpezy/src/decoder/jpezy_decoder.hpp:20,
                 from /home/benben/projects/jpezy/src/decoder/main.cpp:3:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp: In function ‘std::pair<const srook::io::jpeg::v1::bifstream::Byte_n&, srook::io::jpeg::v1::bifstream&> srook::io::jpeg::v1::operator>>(std::pair<const srook::io::jpeg::v1::bifstream::Byte_n&, srook::io::jpeg::v1::bifstream&>, Range&)’:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:230:32: error: no match for ‘operator!=’ (operand types are ‘srook::optionally::v1::optional<int>’ and ‘int’)
  230 |         if (this_.bit_position != 7) {
      |             ~~~~~~~~~~~~~~~~~~ ^~ ~
      |                   |               |
      |                   |               int
      |                   srook::optionally::v1::optional<int>
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:230:32: note: candidate: ‘operator!=(int, int)’ (built-in)
  230 |         if (this_.bit_position != 7) {
      |             ~~~~~~~~~~~~~~~~~~~^~~~
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:230:32: note:   no known conversion for argument 1 from ‘srook::optionally::v1::optional<int>’ to ‘int’
In file included from /home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/bifstream.hpp:5,
                 from /home/benben/projects/jpezy/src/decoder/jpezy_decoder.hpp:20,
                 from /home/benben/projects/jpezy/src/decoder/main.cpp:3:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp: In member function ‘srook::byte* srook::io::jpeg::v1::bifstream::next_address() const’:
/home/benben/projects/jpezy/build/external/SrookCppLibraries/srook/io/jpeg/bifstream.hpp:81:5: warning: control reaches end of non-void function [-Wreturn-type]
   81 |     }
      |     ^
make[2]: *** [CMakeFiles/jpezy_decode.dir/build.make:76:CMakeFiles/jpezy_decode.dir/src/decoder/main.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:139:CMakeFiles/jpezy_decode.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
In file included from /home/benben/projects/jpezy/src/encoder/encode_io.hpp:30,
                 from /home/benben/projects/jpezy/src/encoder/main.cpp:1:
/home/benben/projects/jpezy/src/encoder/jpezy_encoder.hpp: In instantiation of ‘void jpezy::encoder<T>::encode_huffman(int, srook::io::jpeg::v1::bofstream&, const jpezy::huffmanCode_Tb<U, dcs>&, const jpezy::huffmanCode_Tb<U, acs>&, int, int) [with U = int; long unsigned int dcs = 12; long unsigned int acs = 162; T = srook::byte]’:
/home/benben/projects/jpezy/src/encoder/jpezy_encoder.hpp:232:27:   required from ‘void jpezy::encoder<T>::make_MCU(srook::io::jpeg::v1::bofstream&) [with T = srook::byte]’
/home/benben/projects/jpezy/src/encoder/jpezy_encoder.hpp:65:21:   required from ‘std::size_t jpezy::encoder<T>::encode(const char*) [with MODE_TAG = jpezy::COLOR_MODE; T = srook::byte; std::size_t = long unsigned int]’
/home/benben/projects/jpezy/src/encoder/encode_io.hpp:165:63:   required from here
/home/benben/projects/jpezy/src/encoder/jpezy_encoder.hpp:186:16: warning: comparison of integer expressions of different signedness: ‘std::size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  186 |         if (di > static_cast<signed>(dcT.size()))
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 91%] Linking CXX executable jpezy_encode
[ 91%] Built target jpezy_encode
make: *** [Makefile:91:all] 错误 2

Environment

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy
$ uname -a
Linux amd 5.15.0-57-generic #63-Ubuntu SMP Thu Nov 24 13:43:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@falgon
Copy link
Owner

falgon commented Jan 2, 2023

Right, thank you! I'm busy right now, so I can't reproduce it now, but maybe there's a mistake in macro expansion somewhere. Please wait while we investigate... (I think it's a good idea to unwrap with value() as your suggested as a workaround).

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

No branches or pull requests

2 participants