本文整理汇总了C++中list_type::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ list_type::begin方法的具体用法?C++ list_type::begin怎么用?C++ list_type::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类list_type
的用法示例。
在下文中一共展示了list_type::begin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: event_callback
void event_callback(const std::string type, const std::string data, const std::string extra)
{
event_record r;
list_type::iterator record = list_.insert(list_.begin(), r);
record->type = type;
record->data = data;
record->extra = extra;
}
示例2: index
static int index(list_type const & x, value_type const & v)
{
int i = 0;
for(typename list_type::const_iterator it=x.begin(); it!=x.end(); ++it,++i)
{
if( *it == v ) return i;
}
PyErr_SetString(PyExc_ValueError, "Value not in the list");
throw boost::python::error_already_set();
}
示例3: complement
list_type complement(const list_type& list, size_t max)
{
list_type out;
list_type::const_iterator li = list.begin();
for (size_t i = 0; i < max; ++i)
{
if (li != list.end() && *li == i)
++li;
else
out.push_back(i);
}
return out;
}
示例4: pop_type
bool pop_type(const std::string& type)
{
for(list_type::iterator it = list_.begin();
it != list_.end();
it++)
{
if(it->type == type)
{
list_.erase(it);
return true;
}
}
return false;
}
示例5: count_type
int count_type(const std::string& type)
{
int count = 0;
for(list_type::iterator it = list_.begin();
it != list_.end();
it++)
{
if(it->type == type)
{
count++;
}
}
return count;
}
示例6: lb_create_cut
static void lb_create_cut(const par::communicator& comm, unsigned int num_cut,
unsigned int dimen, const list_type& pl, LBData& lbd)
{
#ifndef NDEBUG
if (num_cut > pl.size()-1)
throw std::runtime_error("Cannot create more cuts than points");
#endif
const unsigned int my_rank = comm.rank();
// const unsigned int num_proc = comm.size();
std::vector<real> cut(num_cut);
const unsigned int num_point = pl.size();
unsigned int ipoint = 0;
list_type::const_iterator pit = pl.begin();
for (unsigned int icut=0; icut<num_cut; icut++) {
const unsigned int target = std::round((num_point - ipoint) / (num_cut + 1 - icut));
// std::cout << "icut=" << icut << ", target = " << target << std::endl;
const unsigned int visited = ipoint;
while ((ipoint - visited) < target) {
++pit;
ipoint++;
}
const point_type& p = *pit;
cut[icut] = p[dimen];
}
// allgather number of cuts on each proc
lbd.recvcounts[my_rank] = cut.size();
comm.allgather(lbd.recvcounts.data() + my_rank, 1, lbd.recvcounts.data(), 1);
const unsigned int glob_num_cut =
std::accumulate(lbd.recvcounts.begin(), lbd.recvcounts.end(), 0);
// Resize cut (destroying existing cuts)
lbd.cut.resize(glob_num_cut);
lbd.rdispls[0] = 0;
for (unsigned int i=1; i<lbd.rdispls.size(); i++)
lbd.rdispls[i] = lbd.rdispls[i-1] + lbd.recvcounts[i-1];
// allgatherv into lbd.pointcut
comm.allgatherv(cut.data(), cut.size(), lbd.cut.data(),
lbd.recvcounts.data(), lbd.rdispls.data());
// Sort the cuts
std::sort(lbd.cut.begin(), lbd.cut.end());
}
示例7: set
static void set(list_type & x, int i, value_type const & v)
{
if( i < 0 ) i += x.size();
if( i >= 0 && i < (int)x.size() )
{
iter_type it = x.begin();
for(int pos = 0; pos < i; ++pos) ++it;
*it = v;
}
else
{
PyErr_SetString(PyExc_IndexError, "Index out of range");
boost::python::throw_error_already_set();
}
}
示例8: inverse
list_type inverse(const list_type& src)
{
typedef typename list_type::range_type range_type;
typedef typename list_type::payload_type payload_type;
typedef typename list_type::range_size_type range_size_type;
typedef typename list_type::const_iterator const_iterator;
list_type result( src.limit() );
range_size_type last = 0;
for ( const_iterator i = src.begin(); i != src.end(); ++i )
{
result.insert( range_type( last, i->begin() ) );
last = i->end();
}
result.insert( range_type( last, src.limit() ) );
return result;
}
示例9: rank
//! Calculate rank of a subset A
unsigned int rank(const list_type& list) const
{
list_type out(list.size());
unsigned int max = 0;
for (auto b : m_bases)
{
list_type::iterator end =
std::set_intersection(list.begin(), list.end(),
b.begin(), b.end(),
out.begin());
max = std::max<unsigned int>(max, end - out.begin());
}
return max;
}
示例10: out
//! test if a set of items contains a circuit
bool contains_circuit(const list_type& list) const
{
list_type out(list.size());
for (auto c : m_circuits)
{
list_type::iterator end =
std::set_intersection(list.begin(), list.end(),
c.begin(), c.end(),
out.begin());
if (end == out.begin() + c.size())
{
//std::cout << "contains " << c << std::endl;
return true;
}
}
return false;
}
示例11: halfcomm
static void rcb1d_recurse(const par::communicator& comm, unsigned int dimen,
list_type& pl, LBData& lbd)
{
const unsigned int my_rank = comm.rank();
const unsigned int num_proc = comm.size();
// First: sort list
sort_point2d_list(dimen, pl);
if (num_proc == 1) return;
lbd.change_comm(comm, pl.size());
const list_type::size_type orig_num_point = lbd.size[my_rank];
const unsigned int dim = point_type::dim;
const list_type::size_type glob_num_point =
std::accumulate(lbd.size.begin(), lbd.size.end(), 0);
lbd.cut.resize(num_proc);
lbd.bin.resize(num_proc);
const real ratio = static_cast<real>((num_proc+1) / 2) / num_proc;
list_type::size_type this_offset = ratio * orig_num_point;
const unsigned int rank_midpt = ratio * num_proc;
{
real cut = 0;
int use = 0;
if (orig_num_point > 0) {
const point_type& p = *std::next(pl.begin(), this_offset);
cut = p[dimen];
use = 1;
}
comm.allgather(&cut, 1, lbd.cut.data(), 1);
comm.allgather(&use, 1, lbd.bin.data(), 1);
}
// std::cout << "this_offset = " << this_offset << std::endl;
// std::cout << "ratio = " << ratio << std::endl;
// std::cout << "cuts: ";
// for (auto& p : lbd.cut) std::cout << p << " ";
// std::cout << std::endl;
// std::cout << "use: ";
// for (auto& p : lbd.bin) std::cout << p << " ";
// std::cout << std::endl;
real midpt = 0.;
// std::cout << "my_rank = " << my_rank << std::endl;
// std::cout << "num_proc = " << num_proc << std::endl;
for (unsigned int i=0; i<num_proc; i++)
if (lbd.bin[i] != 0) // include this point
midpt += lbd.cut[i] *
static_cast<real>(lbd.size[i]) /
static_cast<real>(glob_num_point);
list_type other;
list_type::iterator pit = std::find_if(pl.begin(), pl.end(),
[midpt,dimen](const point_type& p)
{ return p[dimen] >= midpt; });
list_type::size_type offset;
if (my_rank < rank_midpt) {
other.splice(other.begin(), pl, pit, pl.end());
offset = pl.size();
}
else {
other.splice(other.begin(), pl, pl.begin(), pit);
offset = other.size();
}
// std::cout << "pl: ";
// for (auto& p : pl) std::cout << p << " ";
// std::cout << std::endl;
// std::cout << "other: ";
// for (auto& p : other) std::cout << p << " ";
// std::cout << std::endl;
// std::cout << "offset = " << offset << std::endl;
lbd.send.resize(other.size() * dim);
{
list_type::iterator it=other.begin();
list_type::size_type i = 0;
while (it != other.end()) {
const point_type& p = *it;
for (unsigned int d=0; d<dim; d++, i++)
lbd.send[i] = p[d];
other.erase(it++);
}
}
// std::cout << "send: ";
// for (auto& p : lbd.send) std::cout << p << " ";
// std::cout << std::endl;
// std::cout << "midpt = " << midpt << std::endl;
// std::cout << "rank_midpt = " << rank_midpt << std::endl;
// std::cout << "this_offset = " << this_offset << std::endl;
// Pack up points
lbd.sendcounts.resize(num_proc);
// Zero out
std::fill(lbd.sendcounts.begin(), lbd.sendcounts.end(), 0);
if (my_rank < rank_midpt) {
//.........这里部分代码省略.........
示例12: in
static bool in(list_type const & x, value_type const & v)
{
return std::find(x.begin(), x.end(), v) != x.end();
}
示例13: contains
bool contains(const list_type& list, size_t item)
{
return std::find(list.begin(), list.end(), item) != list.end();
}