當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::advance方法代碼示例

本文整理匯總了C++中std::advance方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::advance方法的具體用法?C++ std::advance怎麽用?C++ std::advance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::advance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: open_item

void directory_model::open_item(QModelIndex index)
{
    if (index.model() != this)
        return;

    QString text = index.data().toString();
    if (text == "..")
        go_up();

    list<file_info>::iterator file_it = _files.begin();
    advance(file_it, index.row());

    if (file_it->directory)
    {
        if (file_it->link)  // directory link
        {
            string name, to;
            if (_sys->parse_link(file_it->name, name, to))
            {
                fs::path p = _path / name;
                _path_history[p] = *file_it;  // save before change
                change_directory(p, true);
            }
        }
        else // directory
            change_directory(_path / text.toStdString());
    }
}
開發者ID:sansajn,項目名稱:aexplor,代碼行數:28,代碼來源:directory_model.cpp

示例2: remove_item

void directory_model::remove_item(QItemSelectionModel * selection)
{
    if (selection->model() != this)
        return;

    QModelIndexList indexes = selection->selection().indexes();

    vector<list<file_info>::const_iterator> remove_iter_list;
    remove_iter_list.reserve(indexes.size());

    // first, remove from fs
    for (QModelIndex & index : selection->selection().indexes())
    {
        int row = index.row();

        list<file_info>::const_iterator file_it = _files.begin();
        advance(file_it, row);
        remove_iter_list.push_back(file_it);

        _sys->rm(_path / file_it->name);
    }

    beginResetModel();
    for (auto it : remove_iter_list)
        _files.erase(it);
    endResetModel();
}
開發者ID:sansajn,項目名稱:aexplor,代碼行數:27,代碼來源:directory_model.cpp

示例3: remove_evens_and_double_odds

auto remove_evens_and_double_odds(list<int>& data)
{
    for(auto cur = data.begin(); cur != data.end();)
        if (*cur & 0x1)
            cur = data.insert(cur, *cur), advance(cur, 2);
        else
            cur = data.erase(cur);
}
開發者ID:1e0nshe11,項目名稱:Cpp-Primer,代碼行數:8,代碼來源:ex9_31_1.cpp

示例4: main

int main()
{
    forward_list<int> vi = {0,1,2,3,4,5,6,7,8,9};
    auto iter = vi.begin(), prev = vi.before_begin();
    while (iter != vi.end()) {
        if (*iter % 2) {
            iter = vi.insert_after(prev, *iter);
            advance(iter, 2);
            advance(prev, 2);
        } else
            iter = vi.erase_after(prev);
    }

    for (auto i : vi)
        cout << i << " ";

    return 0;
}
開發者ID:Ted2016,項目名稱:CppPrimer,代碼行數:18,代碼來源:ex9_31_2.cpp

示例5: main

int main() {
	auto insert_point = data.begin();
	advance(insert_point, 2);
	istringstream iss("10 20 30");
	copy(istream_iterator<int>(iss), istream_iterator<int>(),
	     inserter(data, insert_point));
	copy(data.begin(), data.end(),
	     ostream_iterator<int>(cout, " "));
	cout << endl;
}
開發者ID:tbfe-de,項目名稱:mc-cppfor,代碼行數:10,代碼來源:inserter2ndArg.cpp

示例6: data

QVariant directory_model::data(QModelIndex const & index, int role) const
{
    switch (role)
    {
    case Qt::EditRole:
    case Qt::DisplayRole:
    {
        if (index.column() == 0 && index.row() < _files.size())
        {
            list<file_info>::const_iterator it = _files.begin();
            advance(it, index.row());
            return QString::fromUtf8(it->name.c_str());
        }
        break;
    }

    case Qt::DecorationRole:
    {
        if (index.column() == 0 && index.row() < _files.size())
        {
            QVariant result;

            list<file_info>::const_iterator it = _files.begin();
            advance(it, index.row());
            if (it->directory)
                result.setValue(get_icon("folder"));
            else if (it->executable)
                result.setValue(get_icon("application-x-executable"));
            else
                result.setValue(get_icon("document-new"));

            return result;
        }
        break;
    }
    }  // switch

    return QVariant{};
}
開發者ID:sansajn,項目名稱:aexplor,代碼行數:39,代碼來源:directory_model.cpp

示例7: displayFrame

void IFPWidget::displayFrame(int fnum)
{
	IFPAnimation* anim = anims[ui.animList->currentRow()];

	IFPAnimation::ObjectIterator it = anim->getObjectBegin();
	advance(it, ui.objList->currentRow());
	IFPObject* obj = *it;

	IFPObject::FrameIterator fit = obj->getFrameBegin();
	advance(fit, fnum);
	IFPRotFrame* frame = *fit;

	Quaternion rot = frame->getRotation();
	ui.frameRotLabel->setText(tr("%1, %2, %3, %4").arg(rot.getX()).arg(rot.getY()).arg(rot.getZ())
			.arg(rot.getW()));

	ui.frameTimeLabel->setText(QString("%1").arg(frame->getTime()));

	if (obj->getFrameType() == IFPObject::RotTransFrame) {
		IFPRotTransFrame* rtframe = (IFPRotTransFrame*) frame;
		Vector3 trans = rtframe->getTranslation();

		ui.frameTransLabel->setText(tr("%1, %2, %3").arg(trans.getX()).arg(trans.getY()).arg(trans.getZ()));
		ui.frameScaleLabel->setText(tr("-"));
	} else if (obj->getFrameType() == IFPObject::RotTransScaleFrame) {
		IFPRotTransScaleFrame* rtsframe = (IFPRotTransScaleFrame*) frame;
		Vector3 trans = rtsframe->getTranslation();
		Vector3 scale = rtsframe->getScale();

		ui.frameTransLabel->setText(tr("%1, %2, %3").arg(trans.getX()).arg(trans.getY()).arg(trans.getZ()));
		ui.frameScaleLabel->setText(tr("%1, %2, %3").arg(scale.getX()).arg(scale.getY()).arg(scale.getZ()));
	} else {
		ui.frameTransLabel->setText(tr("-"));
		ui.frameScaleLabel->setText(tr("-"));
	}
}
開發者ID:alemariusnexus,項目名稱:gtatools,代碼行數:36,代碼來源:IFPWidget.cpp

示例8: setData

bool directory_model::setData(QModelIndex const & index, QVariant const & value, int role)
{
    if (role != Qt::EditRole || index.column() != 0 || index.row() >= _files.size())
        return false;

    string newname = value.toString().toStdString();

    list<file_info>::iterator file_it = _files.begin();
    advance(file_it, index.row());

    if (newname == file_it->name)
        return false;

    rename(file_it->name, newname);
    file_it->name = newname;

    emit dataChanged(index, index);

    return true;
}
開發者ID:sansajn,項目名稱:aexplor,代碼行數:20,代碼來源:directory_model.cpp

示例9: currentObjectChanged

void IFPWidget::currentObjectChanged(int row)
{
	if (row == -1) {
		ui.frameTypeLabel->setText(tr("-"));
		ui.boneIDLabel->setText(tr("-"));
		return;
	}

	IFPAnimation* anim = anims[ui.animList->currentRow()];
	IFPAnimation::ObjectIterator it = anim->getObjectBegin();
	advance(it, row);
	IFPObject* obj = *it;

	switch (obj->getFrameType()) {
	case IFPObject::RotFrame:
		ui.frameTypeLabel->setText(tr("Rotation Frames (Child Frames)"));
		break;
	case IFPObject::RotTransFrame:
		ui.frameTypeLabel->setText(tr("Rotation/Translation Frames (Root Frames)"));
		break;
	case IFPObject::RotTransScaleFrame:
		ui.frameTypeLabel->setText(tr("Rotation/Translation/Scale Frames"));
		break;
	case IFPObject::Unknown2Frame:
		ui.frameTypeLabel->setText(tr("Unknown (FrameType = 2)"));
		break;
	}

	ui.boneIDLabel->setText(QString("%1").arg(obj->getBoneID()));

	printf("Object has %d frames\n", obj->getFrameCount());
	ui.frameNumSpinner->setRange(0, obj->getFrameCount()-1);
	ui.frameNumSlider->setRange(0, obj->getFrameCount()-1);
	ui.frameNumSpinner->setValue(0);
	ui.frameNumSlider->setValue(0);
	displayFrame(0);
}
開發者ID:alemariusnexus,項目名稱:gtatools,代碼行數:37,代碼來源:IFPWidget.cpp

示例10: advance

void Objects::Slideshow::render( double timestamp )
{
  using Graphics::spriteGroup;
  using Graphics::sprites;
  using std::advance;

  // Can't do the initialisation of self_lastUpdate anywhere else
  if ( self_lastUpdate == 0 )
    self_lastUpdate = timestamp;

  // Iterate slides
  if ( self_timeout > 0 and timestamp - self_lastUpdate > self_timeout)
  {
    self_lastUpdate = timestamp;
    self_slidePos++;

    if ( self_slidePos == Graphics::sprites[ self_spriteGroup ] . size() )
      self_slidePos = 0;
  }

  spriteGroup::iterator drawIter = sprites[ self_spriteGroup ].begin();
  advance( drawIter, self_slidePos );
  

  // If there's a sprite at our iterator. (If the group is empty then 
  // begin() is also end() and so not a sprite)
  if ( drawIter != sprites[ self_spriteGroup ] . end() )
  {
    if ( self_coordType == Objects::NORM )
      drawIter -> second -> draw(self_x, self_y, self_w, self_h);

    if ( self_coordType == Objects::NON_NORM )
      drawIter -> second -> draw( (int)self_x, (int)self_y, 
                                         (int)self_w, (int)self_h);
  }
}
開發者ID:VolatileStorm,項目名稱:CernVM-Graphics,代碼行數:36,代碼來源:objects.cpp

示例11: read

void STLRepository::read( const shared_ptr< Query > query, const function< void ( const shared_ptr< Query > ) >& callback )
{
    Resources values;
    Resources resources;
    const auto keys = query->get_keys( );
    
    unique_lock< mutex> lock( m_resources_lock );
    
    if ( not keys.empty( ) )
    {
        for ( const auto& key : keys )
        {
            auto resource = find_if( m_resources.begin( ), m_resources.end( ), [ &key ]( const Resource & resource )
            {
                if ( resource.count( "key" ) == 0 )
                {
                    return false;
                }
                
                return String::lowercase( key ) == String::lowercase( String::to_string( resource.lower_bound( "key" )->second ) );
            } );
            
            if ( resource == m_resources.end( ) )
            {
                query->set_error_code( 40004 );
                return callback( query );
            }
            
            resources.push_back( *resource );
        }
    }
    else
    {
        resources = m_resources;
    }
    
    lock.unlock( );
    
    filter( resources, query->get_inclusive_filters( ), query->get_exclusive_filters( ) ); //just pass query
    
    const auto& index = query->get_index( );
    const auto& limit = query->get_limit( );
    
    if ( index < resources.size( ) and limit not_eq 0 )
    {
        auto start = resources.begin( );
        advance( start, index );
        
        while ( start not_eq resources.end( ) and limit not_eq values.size( ) )
        {
            values.push_back( *start );
            start++;
        }
    }
    
    include( query->get_include( ), values );
    
    auto results = fields( values, query );
    
    query->set_resultset( results );
    callback( query );
}
開發者ID:Corvusoft,項目名稱:restq,代碼行數:62,代碼來源:stl_repository.cpp

示例12: advance

file_info & directory_model::get_file(int row)
{
    auto it = _files.begin();
    advance(it, row);
    return *it;
}
開發者ID:sansajn,項目名稱:aexplor,代碼行數:6,代碼來源:directory_model.cpp

示例13: executeRandomWalkSimulator

//! Execute random walk simulator application mode.
void executeRandomWalkSimulator( 
    const std::string databasePath, 
    const tudat::input_output::parsed_data_vector_utilities::ParsedDataVectorPtr parsedData )
{
    ///////////////////////////////////////////////////////////////////////////

    // Declare using-statements.

    using std::advance;
    using std::cerr;
    using std::cout;
    using std::endl;
    using std::max_element;
    using std::min_element;
    using std::numeric_limits;
    using std::ofstream;
    using std::ostringstream;
    using std::setprecision;
    using std::string;

    using boost::iequals;
    using namespace boost::filesystem; 
    using boost::make_shared;   

    using namespace assist::astrodynamics;
    using namespace assist::basics;
    using namespace assist::mathematics;

    using namespace tudat::basic_astrodynamics::orbital_element_conversions;
    using namespace tudat::basic_mathematics::mathematical_constants;
    using namespace tudat::input_output;
    using namespace tudat::input_output::dictionary;
    using namespace tudat::statistics;

    using namespace stomi::astrodynamics;
    using namespace stomi::database;
    using namespace stomi::input_output;

    ///////////////////////////////////////////////////////////////////////////

    // Extract input parameters.

    // Get dictionary.
    const DictionaryPointer dictionary = getRandomWalkSimulatorDictionary( );

    // Print database path to console.
    cout << "Database                                                  " 
         << databasePath << endl;

    // Extract required parameters. 
    const string randomWalkRunName = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ), 
                findEntry( dictionary, "RANDOMWALKRUN" ) );
    cout << "Random walk run                                           "  
         << randomWalkRunName << endl;  

    // Extract optional parameters. 
    const int numberOfThreads = extractParameterValue< int >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "NUMBEROFTHREADS" ), 1 );
    cout << "Number of threads                                         " 
         << numberOfThreads << endl;  

    const string outputMode = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "OUTPUTMODE" ), "DATABASE" );
    cout << "Output mode                                               "
         << outputMode << endl;          

    const string fileOutputDirectory = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "FILEOUTPUTDIRECTORY" ), "" ) + "/";
    cout << "File output directory                                     "
         << fileOutputDirectory << endl;

    const string randomWalkSimulations = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "RANDOMWALKSIMULATIONS" ), "ALL" );
    cout << "Random walk simulations                                   "
         << randomWalkSimulations << endl;         

    const string randomWalkRunTableName = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "RANDOMWALKRUNTABLENAME" ), "random_walk_run" );
    cout << "Random walk run table                                     " 
         << randomWalkRunTableName << endl;

    const string randomWalkInputTableName = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "RANDOMWALKINPUTTABLENAME" ), "random_walk_input" );
    cout << "Random walk input table                                   " 
         << randomWalkInputTableName << endl;         

    const string randomWalkPerturberTableName = extractParameterValue< string >(
                parsedData->begin( ), parsedData->end( ),
                findEntry( dictionary, "RANDOMWALKPERTURBERTABLENAME" ),
                "random_walk_perturbers" );
    cout << "Random walk perturber table                               "
         << randomWalkPerturberTableName << endl;
//.........這裏部分代碼省略.........
開發者ID:kartikkumar,項目名稱:Stomi,代碼行數:101,代碼來源:randomWalkSimulator.cpp

示例14: wait_some

BidirectionalIterator
wait_some(BidirectionalIterator first, BidirectionalIterator last)
{
  using std::advance;

  if (first == last)
    return first;

  typedef typename std::iterator_traits<BidirectionalIterator>::difference_type
    difference_type;

  bool all_trivial_requests = true;
  difference_type n = 0;
  BidirectionalIterator current = first;
  BidirectionalIterator start_of_completed = last;
  while (true) {
    // Check if we have found a completed request.
    if (optional<status> result = current->test()) {
      using std::iter_swap;

      // We're expanding the set of completed requests
      --start_of_completed;

      // If we have hit the end of the list of pending requests, we're
      // done.
      if (current == start_of_completed)
        return start_of_completed;

      // Swap the request we just completed with the last request that
      // has not yet been tested.
      iter_swap(current, start_of_completed);

      continue;
    }

    // Check if this request (and all others before it) are "trivial"
    // requests, e.g., they can be represented with a single
    // MPI_Request.
    all_trivial_requests =
      all_trivial_requests
      && !current->m_handler
      && current->m_requests[1] == MPI_REQUEST_NULL;

    // Move to the next request.
    ++n;
    if (++current == start_of_completed) {
        // If we have satisfied some requests, we're done.
      if (start_of_completed != last)
        return start_of_completed;

      // We have reached the end of the list. If all requests thus far
      // have been trivial, we can call MPI_Waitsome directly, because
      // it may be more efficient than our busy-wait semantics.
      if (all_trivial_requests) {
        std::vector<MPI_Request> requests;
        std::vector<int> indices(n);
        requests.reserve(n);
        for (current = first; current != last; ++current)
          requests.push_back(current->m_requests[0]);

        // Let MPI wait until some of these operations complete.
        int num_completed;
        BOOST_MPI_CHECK_RESULT(MPI_Waitsome,
                               (n, &requests[0], &num_completed, &indices[0],
                                MPI_STATUSES_IGNORE));

        // Translate the index-based result of MPI_Waitsome into a
        // partitioning on the requests.
        int current_offset = 0;
        current = first;
        for (int index = 0; index < num_completed; ++index) {
          using std::iter_swap;

          // Move "current" to the request object at this index
          advance(current, indices[index] - current_offset);
          current_offset = indices[index];

          // Finish up the request and swap it into the "completed
          // requests" partition.
          current->m_requests[0] = requests[indices[index]];
          --start_of_completed;
          iter_swap(current, start_of_completed);
        }

        // We have satisfied some requests, so we are done.
        return start_of_completed;
      }

      // There are some nontrivial requests, so we must continue our
      // busy waiting loop.
      n = 0;
      current = first;
    }
  }

  // We cannot ever get here
  BOOST_ASSERT(false);
}
開發者ID:AbhinavJain13,項目名稱:turicreate,代碼行數:98,代碼來源:nonblocking.hpp

示例15: wait_any

std::pair<status, ForwardIterator>
wait_any(ForwardIterator first, ForwardIterator last)
{
  using std::advance;

  BOOST_ASSERT(first != last);

  typedef typename std::iterator_traits<ForwardIterator>::difference_type
    difference_type;

  bool all_trivial_requests = true;
  difference_type n = 0;
  ForwardIterator current = first;
  while (true) {
    // Check if we have found a completed request. If so, return it.
    if (current->m_requests[0] != MPI_REQUEST_NULL &&
        (current->m_requests[1] != MPI_REQUEST_NULL ||
         current->m_handler)) {
      if (optional<status> result = current->test())
        return std::make_pair(*result, current);
    }

    // Check if this request (and all others before it) are "trivial"
    // requests, e.g., they can be represented with a single
    // MPI_Request.
    all_trivial_requests =
      all_trivial_requests
      && !current->m_handler
      && current->m_requests[1] == MPI_REQUEST_NULL;

    // Move to the next request.
    ++n;
    if (++current == last) {
      // We have reached the end of the list. If all requests thus far
      // have been trivial, we can call MPI_Waitany directly, because
      // it may be more efficient than our busy-wait semantics.
      if (all_trivial_requests) {
        std::vector<MPI_Request> requests;
        requests.reserve(n);
        for (current = first; current != last; ++current)
          requests.push_back(current->m_requests[0]);

        // Let MPI wait until one of these operations completes.
        int index;
        status stat;
        BOOST_MPI_CHECK_RESULT(MPI_Waitany,
                               (n, &requests[0], &index, &stat.m_status));

        // We don't have a notion of empty requests or status objects,
        // so this is an error.
        if (index == MPI_UNDEFINED)
          boost::throw_exception(exception("MPI_Waitany", MPI_ERR_REQUEST));

        // Find the iterator corresponding to the completed request.
        current = first;
        advance(current, index);
        current->m_requests[0] = requests[index];
        return std::make_pair(stat, current);
      }

      // There are some nontrivial requests, so we must continue our
      // busy waiting loop.
      n = 0;
      current = first;
      all_trivial_requests = true;
    }
  }

  // We cannot ever get here
  BOOST_ASSERT(false);
}
開發者ID:AbhinavJain13,項目名稱:turicreate,代碼行數:71,代碼來源:nonblocking.hpp


注:本文中的std::advance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。