本文整理汇总了C++中Cont类的典型用法代码示例。如果您正苦于以下问题:C++ Cont类的具体用法?C++ Cont怎么用?C++ Cont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zip_var
auto zip_var(LastCont lastContainer) {
Cont<tuple<typename LastCont::value_type>, allocator<tuple<typename LastCont::value_type>>> result;
for_each(lastContainer.begin(), lastContainer.end(), [&](auto &content) {
result.insert(result.end(), make_tuple(content));
});
return result;
}
示例2: test_serialization_helper
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 );
}
示例3: insert
bool insert(T t) {
ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it != elements.end() && t >= it->lb && t <= it->ub) {
return false;
}
ContIter pr = it - 1;
if (it != elements.begin() && pr->ub + 1 == t) {
++pr->ub;
if (it != elements.end() && pr->ub + 1 == it->lb) {
pr->ub = it->ub;
elements.erase(it);
}
}
else if (it != elements.end() && it->lb == t + 1) {
--it->lb;
if (it != elements.begin() && pr->ub + 1 == it->lb) {
pr->ub = it->ub;
elements.erase(it);
}
}
else {
elements.insert(it, interval(t));
}
++_size;
return true;
}
示例4:
//---------------------------------------------------------------------------
void Graph::Visit(int From, Cont & C)
{
if (From >= 0 && From < _Size)
{
int V = From;
bool * Labelled = new bool[_Size];
for(int i = 0; i < _Size; i++)
Labelled[i] = false;
C.Push(V);
Labelled[V] = true;
do
{
V = C.Pop();
printf("%d ", V);
for(int U = 0; U < _Size; U++)
{
if(!Labelled[U] && _m[V][U] != MAXDOUBLE)
{
C.Push(U);
Labelled[U] = true;
}
}
}
while(!C.Empty());
delete [] Labelled;
printf("\n");
}
}
示例5: insert_back
void insert_back(Cont& c, long& avg, const int& num_op)
{
cout << "\nCounting..."
<< "time of " << num_op << " back_insert";
clock_t t = 0;
for(int j = 0; j < REPEAT_TEST; ++j)
{
c.push_back(0);
c.push_back(0);
auto it = c.end();
t = clock();
for (int i = 1; i <= num_op ; ++i)
{
it = c.end();
c.insert(it, i);
}
t = clock() - t;
avg += t;
c.clear();
}
avg /= REPEAT_TEST;
}
示例6: intersect
interval_vector intersect(const interval_vector& o) const {
interval_vector rv;
if (!empty() && !o.empty()) {
ContConstIter a = elements.begin();
ContConstIter b = o.elements.begin();
while (a != elements.end() && b != o.elements.end()) {
while (a != elements.end() && b != o.elements.end() && a->ub < b->lb) {
++a;
}
while (a != elements.end() && b != o.elements.end() && b->ub < a->lb) {
++b;
}
while (a != elements.end() && b != o.elements.end() && a->ub >= b->lb && b->ub >= a->lb) {
const T lb = std::max(a->lb, b->lb);
const T ub = std::min(a->ub, b->ub);
if (!rv.elements.empty() && rv.elements.back().ub + 1 == lb) {
rv.elements.back().ub = ub;
}
else {
rv.elements.push_back(interval(lb, ub));
}
rv._size += ub - lb + 1;
if (a->ub < b->ub) {
++a;
}
else {
++b;
}
}
}
}
return rv;
}
示例7: erase
bool erase(T t) {
ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it == elements.end()) {
return false;
}
if (it->ub < t || it->lb > t) {
return false;
}
if (it->lb == t && it->ub == t) {
elements.erase(it);
--_size;
return true;
}
if (it->ub == t) {
--it->ub;
--_size;
return true;
}
if (it->lb == t) {
++it->lb;
--_size;
return true;
}
if (it->lb < t && it->ub > t) {
elements.insert(it + 1, interval(t + 1, it->ub));
it->ub = t - 1;
--_size;
return true;
}
assert(false && "interval_vector.erase() should never reach this place...");
return false;
}
示例8: operator
void operator()(Cont& c, long count) {
long cnt = count / 100;
for (long i = 0; i < cnt; i++) {
typename Cont::iterator it = c.begin(),
end = c.end();
while (it != end) it++;
}
}
示例9: backInsertion
template<class Cont> void backInsertion(Cont& ci) {
copy(a, a + sizeof(a)/sizeof(Cont::value_type),
back_inserter(ci));
copy(ci.begin(), ci.end(),
ostream_iterator<typename Cont::value_type>(
cout, " "));
cout << endl;
}
示例10: dump
void dump(Cont & container)
{
for (ContIter iter = container.begin(); iter != container.end(); iter++)
{
cout << *iter << " ";
}
cout << endl;
}
示例11: apply
void apply(Cont& c, PtrMemFun f) {
typename Cont::iterator it = c.begin();
while (it != c.end()) {
//(it->*f)(); // Compact form //! gcc-4.4 gcc-4.6 ±àÒ벻ͨ¹ý
((*it).*f)(); // Alternate form
it++;
}
}
示例12: hash_container_object
typename std::enable_if<is_hashable<typename Cont::value_type>::value, void>::type
hash_container_object(const Cont & cont, Hasher & hasher)
{
// some containers don't have size() (ie, forward_list)
size_t d = static_cast<size_t>(std::distance(cont.begin(), cont.end()));
hasher(d);
for(const auto & it : cont)
hasher(it);
}
示例13: midInsertion
void midInsertion(Cont& ci) {
typename Cont::iterator it = ci.begin();
it++;
it++;
it++;
copy(a, a + sizeof(a)/(sizeof(int)*2), inserter(ci, it));
copy(ci.begin(), ci.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
示例14: contains
bool contains(T t) const {
ContConstIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it == elements.end()) {
return false;
}
if (it->ub < t || it->lb > t) {
return false;
}
return true;
}
示例15: insert
iterator insert(value_type&& val) {
if (container.empty()) {
return container.insert(cend(), val);
}
auto elementgreaterthanorequalto = std::lower_bound(cbegin(), cend(), val, std::ref(compare_predicate));
return container.insert(elementgreaterthanorequalto, std::move(val));
}