当前位置: 首页>>代码示例>>C++>>正文


C++ optional::value方法代码示例

本文整理汇总了C++中boost::optional::value方法的典型用法代码示例。如果您正苦于以下问题:C++ optional::value方法的具体用法?C++ optional::value怎么用?C++ optional::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::optional的用法示例。


在下文中一共展示了optional::value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

  std::list<std::pair<typename WeightMap::value_type,
                      std::list<typename Graph::edge_descriptor>>>
  yen_ksp(const Graph& g, Vertex<Graph> s, Vertex<Graph> t,
          WeightMap wm, IndexMap im, boost::optional<unsigned> K, boost::optional<unsigned> length)
  {
    using kr_type = Result<typename WeightMap::value_type, Graph>;

    // The shortest paths - these we return.
    std::list<kr_type> A;

    // An empty result if the source and destination are the same.
    if (s != t)
      {
        // The tentative paths - these are candidate paths.  It's a
        // set, because we want to make sure that a given result can
        // show up in the set of tentative results only once.  The
        // problem is that the algorithm can find the same tentative
        // path many times.
        std::set<kr_type> B;

        // In each iteration we produce the k-th shortest path.
        for (int k = 1; !K || k <= K.value(); ++k) {
			
          if (!yen_ksp(g, s, t, wm, im, A, B)) {
			  // We break the loop if no path was found.
			  break;
          }
          if (length && A.back().second.size() > length.value()) {
			  // We break the loop if the maximum path length was exceeded
			  A.pop_back();
			  break;
		  }
        }
      }

    return A;
  }
开发者ID:nodegoat,项目名称:nodegoat,代码行数:37,代码来源:yen_ksp.hpp

示例2: conn

#include <boost/filesystem.hpp>
#include <gdbplz/connection.hpp>
#include "../Catch/include/catch.hpp"

TEST_CASE("guessing gdb path", "[connection]")
{
	boost::optional<boost::filesystem::path> path = gdbplz::guess_gdb_path();
	REQUIRE((!path || boost::filesystem::exists(path.value())) == true);
}

TEST_CASE("launching with non-existing gdb", "[connection]")
{
	REQUIRE_THROWS_AS([](){
		gdbplz::connection conn("/sfsfsdfwdsfwerfwef/xcvxvfsdfsdfwerwefrsgfdfgdfgergtergdfg");
	}(), gdbplz::gdb_not_found);
}
开发者ID:milleniumbug,项目名称:gdbplz,代码行数:16,代码来源:connection.cpp


注:本文中的boost::optional::value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。