本文整理汇总了C++中std::vector::crend方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::crend方法的具体用法?C++ vector::crend怎么用?C++ vector::crend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::crend方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pos_greater_less_loc
std::size_t indexset::pos_greater_less_loc(const std::vector<irange> & rgs, std::size_t location)
{
std::vector<irange>::const_reverse_iterator it;
for (it = rgs.crbegin(); it != rgs.crend(); ++it) {
std::size_t idx = static_cast<std::size_t>(
std::distance(it, rgs.crend() -1)
);
if (rgs[idx].location() <= location) {
return idx;
}
}
return NotFound;
}
示例2: to_string
std::string to_string() const
{
if (neg)
{
return "-" + (-(*this)).to_string();
}
std::vector<int> decs = { 0 };
for (auto p = digits.crbegin(); p != digits.crend(); ++p)
{
int carryover = 0;
for (auto pdec = decs.begin(); pdec != decs.end(); ++pdec)
{
carryover += *pdec * radix + *p;
*pdec = carryover % 10;
carryover /= 10;
}
while (carryover != 0)
{
decs.push_back(carryover % 10);
carryover /= 10;
}
}
std::string s;
std::transform(decs.crbegin(), decs.crend(), std::back_inserter(s), [](int i){ return '0' + i; });
return s;
}
示例3:
//! Exercise 10.34
inline void
r_print(const std::vector<std::string> &v)
{
std::for_each(v.crbegin(), v.crend(), [](const std::string &s)
{
std::cout << s << " ";
});
}
示例4:
std::vector<std::unique_ptr<std::vector<Node> > >
scc(Graph<Node> &graph, std::vector<Node>& leaders){
std::set<Node> visited;
std::vector< std::unique_ptr<std::vector<Node>> > scc;
for(auto it=leaders.crbegin(); it!=leaders.crend(); ++it){
const auto node = *it;
if(visited.find(node) == visited.end()){
scc.push_back(std::make_unique<std::vector<Node> >());
DFS2(graph, node, visited, *(scc.back()));
}
}
return scc;
}
示例5: printWay
void printWay(const std::vector<State>& way, std::ostream& s)
{
using namespace std;
if (way.empty()) {
s << "no way\n";
return;
}
int n = 0;
for (auto p = way.crbegin(); p != way.crend(); ++p)
{
s << "pos " << n++ << '\n';
s << *p << '\n';
}
}
示例6: insertCandidate
inline void insertCandidate(std::vector<Candidate<SIZE>>& candidates, const Candidate<SIZE>& candidate) {
// this should be fairly efficient, sorting the data to leave the lowest
// cost elements at the end of the list means that we'll be shifting as
// few elements as possible, since we'll consume the lowest cost values
// and insert new candidates based on those, which will also be estimated
// at a cost near to the last consumed value, which will in turn cause them
// to be inserted near the end of the sorted list.
// find the right place
auto i = candidates.crbegin();
while (i != candidates.crend() and candidate > *i) {
++i;
}
auto index = candidates.size() - (i - candidates.crbegin());
// insert the data
candidates.insert(candidates.begin()+index, candidate);
}
示例7:
//TODO: make this function use file hashes instead
std::vector<fs::path> get_dupes_from_files(const std::vector<fs::path> &files)
{
std::vector<fs::path> dupes;
uintmax_t prev = 0, curr = 0;
std::string file_exten_prev, file_exten_curr;
for (auto it = files.crbegin(); it != files.crend(); ++it) //loops in reverse alphabetical order
{
file_exten_curr = it->extension().string();
curr = fs::file_size(*it);
//we assume a file is a duplicate if the file is next to a file alphabetically with the same file size
if (file_exten_curr == file_exten_prev && prev == curr && prev != 0)
{
std::cout << it->filename().string() << std::endl;
dupes.push_back(*it);
}
prev = curr;
file_exten_prev = file_exten_curr;
}
return dupes;
}
示例8: crend
const_reverse_iterator crend() const { return _vector.crend(); }
示例9: Draw
void ClientConsole::Draw( void ) {
if ( !isVisible || !view ) {
return;
}
view->Bind();
const vector4 consoleColour{ 0.0f, 0.0f, 0.0f, 0.5f };
Renderer::DrawQuad(
0, 0, view->width, view->height / 2,
0.0f, 0.0f, 1.0f, 1.0f,
consoleColour,
nullptr
);
Resize();
const uint16_t fontSize = static_cast<uint16_t>( con_fontSize->GetInt32() );
const real32_t x = 0.0f;
vector2 pos = {
x,
(view->height / 2.0f) - font->lineHeight[fontSize]
};
// draw the input line
font->Draw( pos, String::Format( ">%s", input->GetLine() ), fontSize );
// and now the cursor
const char *line = input->GetLine();
real32_t savedX = pos[0];
pos[0] = font->GetGlyphWidth( '>', fontSize );
for ( const char *p = line; *p; p++ ) {
if ( p - line >= static_cast<int32_t>( input->GetCursorPos() ) ) {
break;
}
pos[0] += font->GetGlyphWidth( *p, fontSize );
}
//TODO: overstrike mode
if ( static_cast<uint32_t>( GetElapsedTime() ) & 256 ) {
// flash every 250ms
font->Draw( pos, "_", fontSize );
}
pos[0] = savedX;
// draw version information
static const std::vector<std::string> helpInfoList {
PRODUCT_NAME " on " OS_STRING " (" ARCH_STRING ")",
PRODUCT_VERSION,
};
const uint16_t helpFontSize = 12u;
uint32_t numHelpLinesDrawn = 0u;
for ( auto helpInfo = helpInfoList.crbegin(); helpInfo != helpInfoList.crend(); ++helpInfo ) {
real32_t helpWidth = 0u;
for ( const char *p = (*helpInfo).c_str(); *p; p++ ) {
helpWidth += font->GetGlyphWidth( *p, helpFontSize );
}
const vector2 helpPos = {
view->width - helpWidth,
(view->height / 2)
- (font->lineHeight[helpFontSize] * numHelpLinesDrawn)
- font->lineHeight[fontSize]
- 4u
};
font->Draw( helpPos, *helpInfo, helpFontSize );
numHelpLinesDrawn++;
}
// grab a subset of the console buffer that we may want to draw - we do word-wrapping in realtime
// line breaks and carriage returns are preprocessed in the Console
const uint32_t numLines = console->buffer->size();
const uint32_t start = std::max(
0,
static_cast<int32_t>( numLines )
- static_cast<int32_t>( scrollAmount )
- static_cast<int32_t>( lineCount )
);
const uint32_t begin = std::min( numLines, start );
const uint32_t end = std::min( begin + lineCount, numLines );
std::vector<std::string> lines( console->buffer->begin() + begin, console->buffer->begin() + end );
uint32_t drawn = 0u;
for ( auto line = lines.crbegin(); line != lines.crend(); ++line ) {
// substring of renderable characters
std::vector<std::string> subsets;
Split( *line, subsets );
for ( auto subset = subsets.crbegin(); subset != subsets.crend(); ++subset ) {
const uint32_t subsetLineCount = font->GetTextLineCount( pos, *subset, fontSize );
drawn += subsetLineCount;
if ( drawn > lineCount ) {
break;
}
pos[1] -= font->lineHeight[fontSize] * subsetLineCount;
font->Draw( pos, *subset, fontSize, &colourTable[ColourIndex( COLOUR_WHITE )] );
}
}
}