C++ - får fel som jag inte förstår

Permalänk
Medlem

C++ - får fel som jag inte förstår

Hej,

Jag håller på att skriva om ett litet prestandatest så att man kan välja om det ska köras i multithread-läge eller singlethread-läge. Just nu ger mig g++ detta fel:

g++ -std=c++20 -Wall -o obj/functions.o -c src/functions.cpp g++ -std=c++20 -Wall -o obj/main.o -c src/main.cpp In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = int*; _Value = const std::__cxx11::basic_string<char>]’: /usr/include/c++/11/bits/stl_algobase.h:2069:14: required from ‘constexpr _RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = int*; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const std::__cxx11::basic_string<char> >]’ /usr/include/c++/11/bits/stl_algobase.h:2114:23: required from here src/main.cpp:59:22: in ‘constexpr’ expansion of ‘std::find<int*, std::__cxx11::basic_string<char> >(std::begin<int, 3>(valid_modes), std::end<int, 3>(valid_modes), choice)’ /usr/include/c++/11/bits/stl_algo.h:3884:28: in ‘constexpr’ expansion of ‘std::__find_if<int*, __gnu_cxx::__ops::_Iter_equals_val<const std::__cxx11::basic_string<char> > >(__first, __last, __gnu_cxx::__ops::__iter_equals_val<const std::__cxx11::basic_string<char> >((* & __val)))’ /usr/include/c++/11/bits/predefined_ops.h:270:24: error: no match for ‘operator==’ (operand types are ‘int’ and ‘const std::__cxx11::basic_string<char>’) 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:67, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/stl_iterator.h:1105:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> requires requires(_IteratorL __lhs, _IteratorR __rhs) {{__lhs == __rhs} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];} constexpr bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’ (reversed) 1105 | operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/stl_iterator.h:1105:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33, from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/string:41, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/ext/new_allocator.h:183:9: note: candidate: ‘template<class _Up> constexpr bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<char>&, const __gnu_cxx::new_allocator<_Tp>&)’ (reversed) 183 | operator==(const new_allocator&, const new_allocator<_Up>&) | ^~~~~~~~ /usr/include/c++/11/ext/new_allocator.h:183:9: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const __gnu_cxx::new_allocator<_Tp>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:67, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/stl_iterator.h:494:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&) requires requires{{std::operator==::__x->base() == std::operator==::__y->base()} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];}’ (reversed) 494 | operator==(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/11/bits/stl_iterator.h:494:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::reverse_iterator<_IteratorL>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:67, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/stl_iterator.h:1533:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&) requires requires{{std::operator==::__x->base() == std::operator==::__y->base()} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];}’ (reversed) 1533 | operator==(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/11/bits/stl_iterator.h:1533:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::move_iterator<_IteratorL>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/string:41, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/allocator.h:218:5: note: candidate: ‘template<class _T1, class _T2> constexpr bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)’ (reversed) 218 | operator==(const allocator<_T1>&, const allocator<_T2>&) | ^~~~~~~~ /usr/include/c++/11/bits/allocator.h:218:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::allocator<_CharT>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/basic_string.h:48, from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/string_view:541:5: note: candidate: ‘template<class _CharT, class _Traits> constexpr bool std::operator==(std::basic_string_view<_CharT, _Traits>, std::__type_identity_t<std::basic_string_view<_CharT, _Traits> >)’ (reversed) 541 | operator==(basic_string_view<_CharT, _Traits> __x, | ^~~~~~~~ /usr/include/c++/11/string_view:541:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘std::__cxx11::basic_string<char>’ is not derived from ‘std::basic_string_view<_CharT, _Traits>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/basic_string.h:6248:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)’ (reversed) 6248 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/basic_string.h:6248:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const _CharT*’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/std_thread.h:40, from /usr/include/c++/11/stop_token:35, from /usr/include/c++/11/thread:40, from src/main.cpp:5: /usr/include/c++/11/tuple:1528:5: note: candidate: ‘template<class ... _TElements, class ... _UElements> constexpr bool std::operator==(const std::tuple<_Tps ...>&, const std::tuple<_UTypes ...>&)’ (reversed) 1528 | operator==(const tuple<_TElements...>& __t, | ^~~~~~~~ /usr/include/c++/11/tuple:1528:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::tuple<_Tps ...>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/std_thread.h:44, from /usr/include/c++/11/stop_token:35, from /usr/include/c++/11/thread:40, from src/main.cpp:5: /usr/include/c++/11/bits/unique_ptr.h:753:5: note: candidate: ‘template<class _Tp, class _Dp, class _Up, class _Ep> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, const std::unique_ptr<_Up, _Ep>&)’ (reversed) 753 | operator==(const unique_ptr<_Tp, _Dp>& __x, | ^~~~~~~~ /usr/include/c++/11/bits/unique_ptr.h:753:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/std_thread.h:44, from /usr/include/c++/11/stop_token:35, from /usr/include/c++/11/thread:40, from src/main.cpp:5: /usr/include/c++/11/bits/unique_ptr.h:760:5: note: candidate: ‘template<class _Tp, class _Dp> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, std::nullptr_t)’ (reversed) 760 | operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept | ^~~~~~~~ /usr/include/c++/11/bits/unique_ptr.h:760:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: ‘const std::__cxx11::basic_string<char>’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/ios_base.h:46, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/system_error:368:3: note: candidate: ‘bool std::operator==(const std::error_code&, const std::error_condition&)’ (reversed) 368 | operator==(const error_code& __lhs, const error_condition& __rhs) noexcept | ^~~~~~~~ /usr/include/c++/11/system_error:368:32: note: no known conversion for argument 1 from ‘const std::__cxx11::basic_string<char>’ to ‘const std::error_code&’ 368 | operator==(const error_code& __lhs, const error_condition& __rhs) noexcept | ~~~~~~~~~~~~~~~~~~^~~~~ In file included from /usr/include/c++/11/iosfwd:40, from /usr/include/c++/11/ios:38, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/postypes.h:222:5: note: candidate: ‘template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)’ 222 | operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs) | ^~~~~~~~ /usr/include/c++/11/bits/postypes.h:222:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::fpos<_StateT>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:64, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/stl_pair.h:466:5: note: candidate: ‘template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)’ 466 | operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/11/bits/stl_pair.h:466:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::pair<_T1, _T2>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/basic_string.h:48, from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/string_view:535:5: note: candidate: ‘template<class _CharT, class _Traits> constexpr bool std::operator==(std::basic_string_view<_CharT, _Traits>, std::basic_string_view<_CharT, _Traits>)’ 535 | operator==(basic_string_view<_CharT, _Traits> __x, | ^~~~~~~~ /usr/include/c++/11/string_view:535:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘std::basic_string_view<_CharT, _Traits>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/basic_string.h:6226:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)’ 6226 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/basic_string.h:6226:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/string:55, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/basic_string.h:6234:5: note: candidate: ‘template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::__cxx11::basic_string<_CharT>&, const std::__cxx11::basic_string<_CharT>&)’ 6234 | operator==(const basic_string<_CharT>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/basic_string.h:6234:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::__cxx11::basic_string<_CharT>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/bits/locale_facets.h:48, from /usr/include/c++/11/bits/basic_ios.h:37, from /usr/include/c++/11/ios:44, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/streambuf_iterator.h:226:5: note: candidate: ‘template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)’ 226 | operator==(const istreambuf_iterator<_CharT, _Traits>& __a, | ^~~~~~~~ /usr/include/c++/11/bits/streambuf_iterator.h:226:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::istreambuf_iterator<_CharT, _Traits>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/tuple:39, from /usr/include/c++/11/bits/std_thread.h:40, from /usr/include/c++/11/stop_token:35, from /usr/include/c++/11/thread:40, from src/main.cpp:5: /usr/include/c++/11/array:276:5: note: candidate: ‘template<class _Tp, long unsigned int _Nm> constexpr bool std::operator==(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)’ 276 | operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) | ^~~~~~~~ /usr/include/c++/11/array:276:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::array<_Tp, _Nm>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/vector:67, from src/main.cpp:7: /usr/include/c++/11/bits/stl_vector.h:1892:5: note: candidate: ‘template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)’ 1892 | operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) | ^~~~~~~~ /usr/include/c++/11/bits/stl_vector.h:1892:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/predefined_ops.h:270:24: note: mismatched types ‘const std::vector<_Tp, _Alloc>’ and ‘int’ 270 | { return *__it == _M_value; } | ~~~~~~^~~~~~~~~~~ In file included from /usr/include/c++/11/string:41, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/bits/allocator.h:204:7: note: candidate: ‘constexpr bool std::operator==(const std::allocator<char>&, const std::allocator<char>&)’ 204 | operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW | ^~~~~~~~ /usr/include/c++/11/bits/allocator.h:204:18: note: no known conversion for argument 1 from ‘int’ to ‘const std::allocator<char>&’ 204 | operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW | ^~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/bits/ios_base.h:46, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from src/main.cpp:1: /usr/include/c++/11/system_error:362:3: note: candidate: ‘bool std::operator==(const std::error_code&, const std::error_code&)’ 362 | operator==(const error_code& __lhs, const error_code& __rhs) noexcept | ^~~~~~~~ /usr/include/c++/11/system_error:362:32: note: no known conversion for argument 1 from ‘int’ to ‘const std::error_code&’ 362 | operator==(const error_code& __lhs, const error_code& __rhs) noexcept | ~~~~~~~~~~~~~~~~~~^~~~~ /usr/include/c++/11/system_error:376:3: note: candidate: ‘bool std::operator==(const std::error_condition&, const std::error_condition&)’ 376 | operator==(const error_condition& __lhs, | ^~~~~~~~ /usr/include/c++/11/system_error:376:37: note: no known conversion for argument 1 from ‘int’ to ‘const std::error_condition&’ 376 | operator==(const error_condition& __lhs, | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ In file included from /usr/include/c++/11/stop_token:35, from /usr/include/c++/11/thread:40, from src/main.cpp:5: /usr/include/c++/11/bits/std_thread.h:281:3: note: candidate: ‘bool std::operator==(std::thread::id, std::thread::id)’ 281 | operator==(thread::id __x, thread::id __y) noexcept | ^~~~~~~~ /usr/include/c++/11/bits/std_thread.h:281:25: note: no known conversion for argument 1 from ‘int’ to ‘std::thread::id’ 281 | operator==(thread::id __x, thread::id __y) noexcept | ~~~~~~~~~~~^~~ make: *** [Makefile:47: obj/main.o] Error 1

Min kod ser ut så här (ursäkta stilen, håller fortfarande på att lära mig):

#include <iostream> #include <chrono> #include <string> #include <cstdlib> #include <thread> #include <cmath> #include <vector> #include <numeric> #include <atomic> #include "include/functions.h" void primes_in_range(uint64_t lower_limit, uint64_t upper_limit); std::atomic<unsigned int> prime_count = 0; int main() { using namespace std::chrono_literals; int thread_count = std::thread::hardware_concurrency(); switch (thread_count) { case 0: std::cout << "Implementation does not seem to support 'std::thread::hardware_concurrency()'." << '\n'; std::exit(EXIT_FAILURE); case 1: std::cout << "System only suppports a single thread." << '\n'; break; default: std::cout << "System supports " << thread_count << " threads." << '\n'; break; } constexpr int repeat_val = 10; uint64_t iteration_length_arr[repeat_val]; long double avg_search_time = 0.0; constexpr uint64_t lower_search_limit = 1; constexpr uint64_t upper_search_limit = 100000000; int remainder_range_start = 0; int remainder_range_end = 0; uint64_t start_of_range[thread_count] = {}; uint64_t end_of_range[thread_count] = {}; std::string choice; std::string yes_choices[] = {"Y", "y", "Yes", "yes"}; std::string no_choices[] = {"N", "n", "No", "no"}; int valid_modes[] = {0, 1, 2}; int mode_select = 0; std::chrono::_V2::steady_clock::time_point prog_start_time; std::chrono::_V2::steady_clock::time_point prog_stop_time; uint64_t prog_runtime_nanoseconds = 0; std::chrono::duration<uint64_t, std::nano> elapsed_prog_runtime; ldiv_t result; while (true) { std::cout << "Select benchmark mode from list below:" << '\n'; std::cout << "0. Single-threaded benchmark." << '\n'; std::cout << "1. Multi-threaded benchmark (" << thread_count << " threads)." << '\n'; std::cout << "2. Exit program." << '\n'; std::cout << "Enter one of the listed values: "; std::cin >> mode_select; if (std::find(std::begin(valid_modes), std::end(valid_modes), choice) != std::end(valid_modes)) { break; } else { std::cout << "Invalid mode select, try again!" << '\n'; } } switch (mode_select) { case 0: //Singlethreaded. std::cout << "Starting singlethreaded benchmark..." << '\n'; prog_start_time = std::chrono::steady_clock::now(); for (int k = 0; k < repeat_val; k++) { std::cout << "Iteration " << (k + 1) << " of " << repeat_val << " Runtime (ns): "; auto iteration_start_time = std::chrono::steady_clock::now(); primes_in_range(lower_search_limit, upper_search_limit); auto iteration_stop_time = std::chrono::steady_clock::now(); std::chrono::duration<uint64_t, std::nano> elapsed_single_iteration = iteration_stop_time - iteration_start_time; //how many nanoseconds have elapsed. iteration_length_arr[k] = elapsed_single_iteration.count(); //store elapsed_single_iteration nanoseconds in iteration_length_arr. std::cout << elapsed_single_iteration.count() << '\n'; } avg_search_time = std::accumulate(std::begin(iteration_length_arr), std::end(iteration_length_arr), avg_search_time) / repeat_val; prog_stop_time = std::chrono::steady_clock::now(); elapsed_prog_runtime = prog_stop_time - prog_start_time; //how many nanoseconds have elapsed. prog_runtime_nanoseconds = elapsed_prog_runtime.count(); std::cout << "Prime singlethreaded benchmark is done!" << '\n'; std::cout << "\n**** Results ****" << '\n'; std::cout << "Program ran for total of (DD:HH:MM:SS.SSSSSSSSS): " << func::to_days_hours_minutes_seconds(prog_runtime_nanoseconds) << '\n'; std::cout << "\n"; std::cout << "Program ran for: " << prog_runtime_nanoseconds << " ns" << '\n'; std::cout << "\n"; std::cout << "Average time to find all primes between " << lower_search_limit << " and " << upper_search_limit << " was (DD:HH:MM:SS.SSSSSSSSS):" << '\n'; std::cout << func::to_days_hours_minutes_seconds((uint64_t) avg_search_time) << '\n'; std::cout << "\n"; std::cout << "Average search time: " << (uint64_t) avg_search_time << " ns" << '\n'; std::cout << "Number of primes found is: " << prime_count / repeat_val << '\n'; break; case 1: //Multithreaded. result = std::div(upper_search_limit, (long) thread_count); std::cout << "Numerator: " << upper_search_limit << '\n'; std::cout << "Denominator (also how many threads): " << thread_count << '\n'; std::cout << "Quotient: " << result.quot << '\n'; std::cout << "Remainder: " << result.rem << '\n'; std::cout << " **** " << '\n'; //Calculating start and end vales for the ranges. for (int i = 0; i < thread_count; i++) { if (i == 0) { start_of_range[i] = lower_search_limit; end_of_range[i] = result.quot; } else { start_of_range[i] = end_of_range[i - 1] + 1; end_of_range[i] = (start_of_range[i] - 1) + result.quot; } } //Calculating start and end values for remainder range. if (result.rem != 0) { remainder_range_start = (upper_search_limit - result.rem) + 1; remainder_range_end = upper_search_limit; } /* std::cout << "Start prime_threads between " << lower_search_limit << " and " << upper_search_limit << "? [Y/n]: "; std::cin >> choice; if (std::find(std::begin(yes_choices), std::end(yes_choices), choice) != std::end(yes_choices)) { */ std::cout << "Starting multithreaded prime benchmark..." << '\n'; prog_start_time = std::chrono::steady_clock::now(); for (int k = 0; k < repeat_val; k++) { std::cout << "Iteration " << (k + 1) << " of " << repeat_val << " Runtime (ns): "; //Create vector to hold main thread objects. std::vector<std::thread> main_threads; auto iteration_start_time = std::chrono::steady_clock::now(); //Create and start main threads. for (int i = 0; i < thread_count; i++) { main_threads.push_back(std::thread(primes_in_range, start_of_range[i], end_of_range[i])); } //Join main threads. for (auto &th : main_threads) { th.join(); } //Create remainder thread (if needed). if (result.rem != 0) { std::thread remainder_thread = std::thread(primes_in_range, remainder_range_start, remainder_range_end); remainder_thread.join(); } auto iteration_stop_time = std::chrono::steady_clock::now(); std::chrono::duration<uint64_t, std::nano> elapsed_single_iteration = iteration_stop_time - iteration_start_time; //how many nanoseconds have elapsed. iteration_length_arr[k] = elapsed_single_iteration.count(); //store elapsed_single_iteration nanoseconds in iteration_length_arr. std::cout << elapsed_single_iteration.count() << '\n'; } avg_search_time = std::accumulate(std::begin(iteration_length_arr), std::end(iteration_length_arr), avg_search_time) / repeat_val; prog_stop_time = std::chrono::steady_clock::now(); elapsed_prog_runtime = prog_stop_time - prog_start_time; //how many nanoseconds have elapsed. prog_runtime_nanoseconds = elapsed_prog_runtime.count(); std::cout << "Prime multithreaded benchmark is done!" << '\n'; std::cout << "\n**** Results ****" << '\n'; std::cout << "Program ran for total of (DD:HH:MM:SS.SSSSSSSSS): " << func::to_days_hours_minutes_seconds(prog_runtime_nanoseconds) << '\n'; std::cout << "\n"; std::cout << "Program ran for: " << prog_runtime_nanoseconds << " ns" << '\n'; std::cout << "\n"; std::cout << "Average time to find all primes between " << lower_search_limit << " and " << upper_search_limit << " was (DD:HH:MM:SS.SSSSSSSSS):" << '\n'; std::cout << func::to_days_hours_minutes_seconds((uint64_t) avg_search_time) << '\n'; std::cout << "\n"; std::cout << "Average search time: " << (uint64_t) avg_search_time << " ns" << '\n'; std::cout << "Number of primes found is: " << prime_count / repeat_val << '\n'; break; case 2: //Exit program. std::cout << "Exited program." << '\n'; break; default: std::cout << "Defaulted to exiting program since no valid input was made." << '\n'; std::exit(EXIT_FAILURE); } return 0; } void primes_in_range(uint64_t lower_limit, uint64_t upper_limit) { unsigned int count = 0; for (uint64_t i = lower_limit; i < upper_limit + 1; i++) { if (func::prime::is_prime(i)) { count++; } } prime_count += count; }

Jag har inte fått någon bättre förståelse av att googla runt heller. Vad gör jag fel?

Permalänk
Medlem

Kompilatorfel av den typen är inte roliga. Det man får göra är att försöka hitta någon slags indikation på vad som kan tänkas vara fel i koden man själv skrivit. En bit in i felmeddelandet står det något om "main.cpp:59". Dvs något som har med rad 59 i din kod verkar vara fel...

std::string choice; std::string yes_choices[] = {"Y", "y", "Yes", "yes"}; std::string no_choices[] = {"N", "n", "No", "no"}; int valid_modes[] = {0, 1, 2}; int mode_select = 0; std::chrono::_V2::steady_clock::time_point prog_start_time; std::chrono::_V2::steady_clock::time_point prog_stop_time; uint64_t prog_runtime_nanoseconds = 0; std::chrono::duration<uint64_t, std::nano> elapsed_prog_runtime; ldiv_t result; while (true) { std::cout << "Select benchmark mode from list below:" << '\n'; std::cout << "0. Single-threaded benchmark." << '\n'; std::cout << "1. Multi-threaded benchmark (" << thread_count << " threads)." << '\n'; std::cout << "2. Exit program." << '\n'; std::cout << "Enter one of the listed values: "; std::cin >> mode_select; if (std::find(std::begin(valid_modes), std::end(valid_modes), choice) != std::end(valid_modes)) { break;

Rad 59 är den sista if-satsen i den här koden. Vad du har är en std::find() där du skickar in typerna int*, int*, std::string. Det går inte ihop. Antagligen var det mode_select du hade tänkt dig här, men jag orkar inte riktigt kolla igenom för att se om det stämmer.

Sedan är det bara att fortsätta på samma sätt...

Ibland blir man ändå inte klok på det hela och då kan man t ex prova att klippa bort delar av koden som inte borde ha någon betydelse och se om felet försvinner eller ändras, och genom såna ledtrådar lista ut vad problemet är. I det här fallet kanske man t ex hade klippt ner det till följande kod efter mycket jobb och då är felet mycket lättare att se vad felet är (antagligen hade man sett felet långt innan dess, men det illustrerar principen iaf):

int main() { std::string choice; int valid_modes[] = {0, 1, 2}; int mode_select = 0; std::find(std::begin(valid_modes), std::end(valid_modes), choice); return 0; }

Om det fortfarande inte klarnar får man prova att ändra saker, t ex ändra typen av std::string till bool och se vad som händer osv.

En annan strategi är att försöka köra koden genom en annan kompilator och hoppas på att få bättre felmeddelanden från den.

Permalänk
Medlem
Skrivet av trudelutt:

Kompilatorfel av den typen är inte roliga. Det man får göra är att försöka hitta någon slags indikation på vad som kan tänkas vara fel i koden man själv skrivit. En bit in i felmeddelandet står det något om "main.cpp:59". Dvs något som har med rad 59 i din kod verkar vara fel...

std::string choice; std::string yes_choices[] = {"Y", "y", "Yes", "yes"}; std::string no_choices[] = {"N", "n", "No", "no"}; int valid_modes[] = {0, 1, 2}; int mode_select = 0; std::chrono::_V2::steady_clock::time_point prog_start_time; std::chrono::_V2::steady_clock::time_point prog_stop_time; uint64_t prog_runtime_nanoseconds = 0; std::chrono::duration<uint64_t, std::nano> elapsed_prog_runtime; ldiv_t result; while (true) { std::cout << "Select benchmark mode from list below:" << '\n'; std::cout << "0. Single-threaded benchmark." << '\n'; std::cout << "1. Multi-threaded benchmark (" << thread_count << " threads)." << '\n'; std::cout << "2. Exit program." << '\n'; std::cout << "Enter one of the listed values: "; std::cin >> mode_select; if (std::find(std::begin(valid_modes), std::end(valid_modes), choice) != std::end(valid_modes)) { break;

Rad 59 är den sista if-satsen i den här koden. Vad du har är en std::find() där du skickar in typerna int*, int*, std::string. Det går inte ihop. Antagligen var det mode_select du hade tänkt dig här, men jag orkar inte riktigt kolla igenom för att se om det stämmer.

Sedan är det bara att fortsätta på samma sätt...

Ibland blir man ändå inte klok på det hela och då kan man t ex prova att klippa bort delar av koden som inte borde ha någon betydelse och se om felet försvinner eller ändras, och genom såna ledtrådar lista ut vad problemet är. I det här fallet kanske man t ex hade klippt ner det till följande kod efter mycket jobb och då är felet mycket lättare att se vad felet är (antagligen hade man sett felet långt innan dess, men det illustrerar principen iaf):

int main() { std::string choice; int valid_modes[] = {0, 1, 2}; int mode_select = 0; std::find(std::begin(valid_modes), std::end(valid_modes), choice); return 0; }

Om det fortfarande inte klarnar får man prova att ändra saker, t ex ändra typen av std::string till bool och se vad som händer osv.

En annan strategi är att försöka köra koden genom en annan kompilator och hoppas på att få bättre felmeddelanden från den.

Tack! Ska pröva det. Jag är egentligen Java-utvecklare och JDK:n är mycket trevligare när det kommer till felmeddelanden.

EDIT: Repot om ni vill pröva allt själv: https://github.com/AlexLandherr/prime_threads

Permalänk
Medlem

Jag blir nyfiken - vad det är för system du försöker kompilera på? Kanske du kan göra en "g++ -v" och posta resultatet här - jag sitter på en Debian 11 och då fungerar det fint att kompilera. (Och då tänker jag att paketversionerna i en sådan är ju äldre än det mesta, så därför blir jag nyfiken på vad du sitter på för system)...

gusnan@debian-i7:~ > g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.1 20210110 (Debian 10.2.1-6)

Permalänk
Medlem

std::string choice;
int valid_modes[] = {0, 1, 2};
if (std::find(std::begin(valid_modes), std::end(valid_modes), choice) != std::end(valid_modes)) {
// stuff
}

Gör om valid_modes till en std::array<std::string>. Du försöker leta efter en string i en int-array.

Permalänk
Medlem

Alla fel som detekterades i kompileringen har fixats; se repot:
https://github.com/AlexLandherr/prime_threads

Permalänk
Medlem
Skrivet av Apollo11:

Alla fel som detekterades i kompileringen har fixats; se repot:
https://github.com/AlexLandherr/prime_threads

Och det hade du så klart redan innan jag hämtade från git-förrådet och kommenterade? Meh.