Home | History | Annotate | Download | only in bitset.members
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // test bitset<N>& set(size_t pos, bool val = true);
     11 
     12 #include <bitset>
     13 #include <cassert>
     14 #include <stdexcept>
     15 
     16 #include "test_macros.h"
     17 
     18 template <std::size_t N>
     19 void test_set_one(bool test_throws)
     20 {
     21     std::bitset<N> v;
     22 #ifdef TEST_HAS_NO_EXCEPTIONS
     23     if (test_throws) return;
     24 #else
     25     try
     26 #endif
     27     {
     28         v.set(50);
     29         if (50 >= v.size())
     30             assert(false);
     31         assert(v[50]);
     32         assert(!test_throws);
     33     }
     34 #ifndef TEST_HAS_NO_EXCEPTIONS
     35     catch (std::out_of_range&)
     36     {
     37         assert(test_throws);
     38     }
     39     try
     40 #endif
     41     {
     42         v.set(50, false);
     43         if (50 >= v.size())
     44             assert(false);
     45         assert(!v[50]);
     46         assert(!test_throws);
     47     }
     48 #ifndef TEST_HAS_NO_EXCEPTIONS
     49     catch (std::out_of_range&)
     50     {
     51         assert(test_throws);
     52     }
     53 #endif
     54 }
     55 
     56 int main()
     57 {
     58     test_set_one<0>(true);
     59     test_set_one<1>(true);
     60     test_set_one<31>(true);
     61     test_set_one<32>(true);
     62     test_set_one<33>(true);
     63     test_set_one<63>(false);
     64     test_set_one<64>(false);
     65     test_set_one<65>(false);
     66     test_set_one<1000>(false);
     67 }
     68