fork download
  1. #include <iostream>
  2. #include <bitset>
  3.  
  4. enum class flag {
  5. borderless,
  6. resizable
  7. };
  8.  
  9. using flags = std::bitset<sizeof (flag)>;
  10.  
  11. void window(flags f)
  12. {
  13. if (f[flag::borderless])
  14. std::cout << "borderless is set\n";
  15. if (f[flag::resizable])
  16. std::cout << "resizable is set\n";
  17. }
  18.  
  19. int main() {
  20. std::cout << "== none\n";
  21. window({});
  22.  
  23. std::cout << "== borderless\n";
  24. window(flags(flag::borderless));
  25.  
  26.  
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void window(flags)’:
prog.cpp:13:7: error: no match for ‘operator[]’ (operand types are ‘flags {aka std::bitset<4ul>}’ and ‘flag’)
  if (f[flag::borderless])
       ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:1155:7: note: candidate: std::bitset<_Nb>::reference std::bitset<_Nb>::operator[](std::size_t) [with long unsigned int _Nb = 4ul; std::size_t = long unsigned int]
       operator[](size_t __position)
       ^~~~~~~~
/usr/include/c++/6/bitset:1155:7: note:   no known conversion for argument 1 from ‘flag’ to ‘std::size_t {aka long unsigned int}’
/usr/include/c++/6/bitset:1159:7: note: candidate: constexpr bool std::bitset<_Nb>::operator[](std::size_t) const [with long unsigned int _Nb = 4ul; std::size_t = long unsigned int]
       operator[](size_t __position) const
       ^~~~~~~~
/usr/include/c++/6/bitset:1159:7: note:   no known conversion for argument 1 from ‘flag’ to ‘std::size_t {aka long unsigned int}’
prog.cpp:15:7: error: no match for ‘operator[]’ (operand types are ‘flags {aka std::bitset<4ul>}’ and ‘flag’)
  if (f[flag::resizable])
       ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:1155:7: note: candidate: std::bitset<_Nb>::reference std::bitset<_Nb>::operator[](std::size_t) [with long unsigned int _Nb = 4ul; std::size_t = long unsigned int]
       operator[](size_t __position)
       ^~~~~~~~
/usr/include/c++/6/bitset:1155:7: note:   no known conversion for argument 1 from ‘flag’ to ‘std::size_t {aka long unsigned int}’
/usr/include/c++/6/bitset:1159:7: note: candidate: constexpr bool std::bitset<_Nb>::operator[](std::size_t) const [with long unsigned int _Nb = 4ul; std::size_t = long unsigned int]
       operator[](size_t __position) const
       ^~~~~~~~
/usr/include/c++/6/bitset:1159:7: note:   no known conversion for argument 1 from ‘flag’ to ‘std::size_t {aka long unsigned int}’
prog.cpp: In function ‘int main()’:
prog.cpp:24:31: error: no matching function for call to ‘std::bitset<4ul>::bitset(flag)’
  window(flags(flag::borderless));
                               ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:938:9: note: candidate: template<class _CharT> std::bitset<_Nb>::bitset(const _CharT*, typename std::__cxx11::basic_string<_CharT>::size_type, _CharT, _CharT)
         bitset(const _CharT* __str,
         ^~~~~~
/usr/include/c++/6/bitset:938:9: note:   template argument deduction/substitution failed:
prog.cpp:24:31: note:   mismatched types ‘const _CharT*’ and ‘flag’
  window(flags(flag::borderless));
                               ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:917:2: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::bitset<_Nb>::bitset(const std::__cxx11::basic_string<_CharT2, _Traits2, _Alloc>&, std::size_t, std::size_t, _CharT, _CharT)
  bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __s,
  ^~~~~~
/usr/include/c++/6/bitset:917:2: note:   template argument deduction/substitution failed:
prog.cpp:24:31: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘flag’
  window(flags(flag::borderless));
                               ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:906:2: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::bitset<_Nb>::bitset(const std::__cxx11::basic_string<_CharT2, _Traits2, _Alloc>&, std::size_t, std::size_t)
  bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __s,
  ^~~~~~
/usr/include/c++/6/bitset:906:2: note:   template argument deduction/substitution failed:
prog.cpp:24:31: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘flag’
  window(flags(flag::borderless));
                               ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:885:2: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::bitset<_Nb>::bitset(const std::__cxx11::basic_string<_CharT2, _Traits2, _Alloc>&, std::size_t)
  bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __s,
  ^~~~~~
/usr/include/c++/6/bitset:885:2: note:   template argument deduction/substitution failed:
prog.cpp:24:31: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘flag’
  window(flags(flag::borderless));
                               ^
In file included from prog.cpp:2:0:
/usr/include/c++/6/bitset:866:17: note: candidate: constexpr std::bitset<_Nb>::bitset(long long unsigned int) [with long unsigned int _Nb = 4ul]
       constexpr bitset(unsigned long long __val) noexcept
                 ^~~~~~
/usr/include/c++/6/bitset:866:17: note:   no known conversion for argument 1 from ‘flag’ to ‘long long unsigned int’
/usr/include/c++/6/bitset:861:26: note: candidate: constexpr std::bitset<_Nb>::bitset() [with long unsigned int _Nb = 4ul]
       _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT
                          ^~~~~~
/usr/include/c++/6/bitset:861:26: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/6/bitset:747:11: note: candidate: constexpr std::bitset<4ul>::bitset(const std::bitset<4ul>&)
     class bitset
           ^~~~~~
/usr/include/c++/6/bitset:747:11: note:   no known conversion for argument 1 from ‘flag’ to ‘const std::bitset<4ul>&’
/usr/include/c++/6/bitset:747:11: note: candidate: constexpr std::bitset<4ul>::bitset(std::bitset<4ul>&&)
/usr/include/c++/6/bitset:747:11: note:   no known conversion for argument 1 from ‘flag’ to ‘std::bitset<4ul>&&’
stdout
Standard output is empty