void test_serialization_helper() { Cont vec; set_capacity<Cont>()( vec ); add( vec, new Base( -1 ), 0u ); add( vec, new Derived( 1 ), 1u ); BOOST_CHECK_EQUAL( vec.size(), 2u ); std::ofstream ofs("filename"); OArchive oa(ofs); oa << boost::serialization::make_nvp( "container", as_const(vec) ); ofs.close(); std::ifstream ifs("filename", std::ios::binary); IArchive ia(ifs); Cont vec2; ia >> boost::serialization::make_nvp( "container", vec2 ); ifs.close(); BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); BOOST_CHECK_EQUAL( (*vec2.begin()).i, -1 ); BOOST_CHECK_EQUAL( (*++vec2.begin()).i, 0 ); typename Cont::iterator i = vec2.begin(); ++i; Derived* d = dynamic_cast<Derived*>( &*i ); BOOST_CHECK_EQUAL( d->i2, 1 ); }
inline void GAppSetOpts_ranged(const char *value, Cont& cont) { cont.clear(); bool had_range = false; const char *comma = value; do { uint32_t low = abs(atoi(comma)), high = low; const char *delim = strchr(comma, '-'); const char *nextc = strchr(comma, ','); if (delim && (nextc == 0 || nextc > delim)) { had_range = true; high = abs(atoi(delim + 1)); } for (; low <= high; ++low) { cont.push_back(low); } } while ((comma = strchr(comma, ',')) != 0 && ++comma && *comma != 0); if (cont.size() == 1 && !had_range) { uint32_t val = cont.front(); cont.clear(); for (uint32_t i = 1; i <= val; ++i) { cont.push_back(i); } } }
void test_serialization_helper() { Cont vec; add( vec, new Base( -1 ), 0u ); add( vec, new Derived( 1 ), 1u ); std::ofstream ofs("filename"); boost::archive::text_oarchive oa(ofs); oa << as_const(vec); ofs.close(); std::ifstream ifs("filename", std::ios::binary); boost::archive::text_iarchive ia(ifs); Cont vec2; ia >> vec2; ifs.close(); BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); BOOST_CHECK_EQUAL( (*vec2.begin()).i, -1 ); BOOST_CHECK_EQUAL( (*--vec2.end()).i, 0 ); typename Cont::iterator i = vec2.end(); --i; Derived* d = dynamic_cast<Derived*>( &*i ); BOOST_CHECK_EQUAL( d->i2, 1 ); }
NumericT average(const Cont<NumericT>& vals) const { std::cout << "lin average " << std::endl; if (vals.size() == 0) return NumericT(0.); // Concept:: neutral element double dval(0.0); for (unsigned int i(0); i < vals.size(); ++i) { double dv(*vals[i]); dval += dv; } dval = dval/(double(vals.size())); return NumericT(dval); }
static void do_move(Cont& styls, int type, int& first, int& last, bool storage) { auto begin = styls.begin(); // Move up if (type == 0) { if (first == 0) return; rotate(begin + first - 1, begin + first, begin + last + 1); first--; last--; } // Move to top else if (type == 1) { rotate(begin, begin + first, begin + last + 1); last = last - first; first = 0; } // Move down else if (type == 2) { if (last + 1 == (int)styls.size()) return; rotate(begin + first, begin + last + 1, begin + last + 2); first++; last++; } // Move to bottom else if (type == 3) { rotate(begin + first, begin + last + 1, styls.end()); first = styls.size() - (last - first + 1); last = styls.size() - 1; } // Sort else if (type == 4) { // Get confirmation if (storage) { int res = wxMessageBox(_("Are you sure? This cannot be undone!"), _("Sort styles"), wxYES_NO | wxCENTER); if (res == wxNO) return; } sort(styls.begin(), styls.end(), cmp_name()); first = 0; last = 0; } }
void operator()(Cont& c, long count) { long cnt = count * 10; if (cnt > c.size()) { cout << "RemoveBack: not enough elements" << endl; return; } for (long i = 0; i < cnt; i++) c.pop_back(); }
inline std::enable_if_t<std::is_base_of<T, std::decay_t<U>>::value> push(U&& value) { std::unique_lock<std::mutex> lock(mut); // only add the value on the stack if there is room data_cond.wait(lock, [this]{ return (data_queue.size() < capacity) || shutdownFlag; }); data_queue.emplace(std::make_shared< std::decay_t<U>> (std::forward<U>(value))); data_cond.notify_one(); }
void operator()(Cont& c, long count) { int middle = c.size() / 2; typename Cont::iterator it = c.begin(), mid = c.begin(); it++; // Put it in the middle for (int x = 0; x < middle + 1; x++) mid++; long cnt = count * 10; for (long i = 0; i < cnt; i++) swap(*it, *mid); }
inline std::enable_if_t<std::is_base_of<T, U>::value> push(std::shared_ptr<U>&& ptr) { std::unique_lock<std::mutex> lock(mut); // only add the value on the stack if there is room data_cond.wait(lock, [this]{ return (data_queue.size() < capacity) || shutdownFlag; }); if (!shutdownFlag) { data_queue.emplace(std::move(ptr)); // move the pointer } data_cond.notify_one(); }
void operator()(Cont& c, long count) { long cnt = count / 10; if (cnt > c.size()) { cout << "RemoveMiddle: not enough elements" << endl; return; } for (long i = 0; i < cnt; i++) { typename Cont::iterator it = c.begin(); it++; c.erase(it); } }
NumericT average(const Cont<NumericT>& vals) const { if (vals.size() == 0) return NumericT(0.); double dval(0.0); int dcnt(0); for (unsigned int i(0); i < vals.size(); ++i) { double dv((vals[i])); if (dv <= 0.0) continue; dv = log(dv); dval += dv; dcnt++; } if (dcnt == 0) return NumericT(0.); dval = exp(dval/double(dcnt)); return NumericT(dval); }
static size_type size(Cont const &cont) { return cont.size(); }
size_type size() const { return container.size(); }
inline bool check_empty(const Cont &c) { return c.empty() && c.size() == 0 && c.begin() == c.end(); }
com_ptr<ID3D11Buffer> create_i_buffer(device_type device, UINT cpu_access_flags, D3D11_USAGE usage, const Cont& cont) { return create_i_buffer(device, cpu_access_flags, usage, sizeof(Cont::value_type) * cont.size()); }
void operator()(Cont& c, long count) { int sz = c.size(); long cnt = count * 100; for (long i = 0; i < cnt; i++) c[rand() % sz]; }
inline typename Cont::size_type max() const { return not_prime.size()-1; }