• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ optional类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中optional的典型用法代码示例。如果您正苦于以下问题:C++ optional类的具体用法?C++ optional怎么用?C++ optional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1:

void
ThreadedLoader::load_patch(bool                              merge,
                           const Glib::ustring&              document_uri,
                           optional<Path>                    engine_parent,
                           optional<Symbol>                  engine_symbol,
                           optional<GraphObject::Properties> engine_data)
{
	_mutex.lock();

	Ingen::Shared::World* world = App::instance().world();

	Glib::ustring engine_base = "";
	if (engine_parent) {
		if (merge)
			engine_base = engine_parent.get().str();
		else
			engine_base = engine_parent.get().base();
	}

	_events.push_back(
		sigc::hide_return(
			sigc::bind(sigc::mem_fun(world->parser().get(),
			                         &Ingen::Serialisation::Parser::parse_file),
			           App::instance().world(),
			           App::instance().world()->engine().get(),
			           document_uri,
			           engine_parent,
			           engine_symbol,
			           engine_data)));

	whip();

	_mutex.unlock();
}
开发者ID:pgiblock,项目名称:ingen,代码行数:34,代码来源:ThreadedLoader.cpp


示例2: LD

/// Stores a file generated by a test case into the database as a BLOB.
///
/// \param name The name of the file to store in the database.  This needs to be
///     unique per test case.  The caller is free to decide what names to use
///     for which files.  For example, it might make sense to always call
///     __STDOUT__ the stdout of the test case so that it is easy to locate.
/// \param path The path to the file to be stored.
/// \param test_case_id The identifier of the test case this file belongs to.
///
/// \return The identifier of the stored file, or none if the file was empty.
///
/// \throw store::error If there are problems writing to the database.
optional< int64_t >
store::write_transaction::put_test_case_file(const std::string& name,
                                             const fs::path& path,
                                             const int64_t test_case_id)
{
    LD(F("Storing %s (%s) of test case %s") % name % path % test_case_id);
    try {
        const optional< int64_t > file_id = put_file(_pimpl->_db, path);
        if (!file_id) {
            LD("Not storing empty file");
            return none;
        }

        sqlite::statement stmt = _pimpl->_db.create_statement(
            "INSERT INTO test_case_files (test_case_id, file_name, file_id) "
            "VALUES (:test_case_id, :file_name, :file_id)");
        stmt.bind(":test_case_id", test_case_id);
        stmt.bind(":file_name", name);
        stmt.bind(":file_id", file_id.get());
        stmt.step_without_results();

        return optional< int64_t >(_pimpl->_db.last_insert_rowid());
    } catch (const sqlite::error& e) {
        throw error(e.what());
    }
}
开发者ID:jmmv,项目名称:kyua,代码行数:38,代码来源:write_transaction.cpp


示例3: cowsay

void cowsay(Console & drawConsole, const string & name,
            const optional<string> & text,
            const optional<int> & xOffset,
            bool noSkip)
{
    const auto image = loadImage(name + ".bmp");

    ConsoleStuff console;

    if (text)
    {
        auto wordWidth = image.Width() / console.GetFontSize().X;
        if (text.get().size() < wordWidth)
        {
            wordWidth = text.get().size();
        }
        wordBubble(text.get(), (image.Width() / console.GetFontSize().X));
    }

    const int linesToSkip = noSkip ? 0
                                   : image.Height() / console.GetFontSize().Y;

    for (size_t n = 0; n < linesToSkip; ++ n) {
        std::cout << "\n";
    }

    auto textCoordinates = console.GetTextCoordinates();
    auto c = console.ToPixelCoordinates(
        {textCoordinates.X + xOffset.get_value_or(0),
         textCoordinates.Y - linesToSkip});

    drawCow(drawConsole, c, image);
}
开发者ID:TimSimpson,项目名称:CpCowsay,代码行数:33,代码来源:cowsay.cpp


示例4: main

int main()
{
    {
        const optional<X> opt; ((void)opt);
        ASSERT_NOT_NOEXCEPT(opt.value());
        ASSERT_SAME_TYPE(decltype(opt.value()), X const&);
    }
    {
        constexpr optional<X> opt(in_place);
        static_assert(opt.value().test() == 3, "");
    }
    {
        const optional<X> opt(in_place);
        assert(opt.value().test() == 3);
    }
#ifndef TEST_HAS_NO_EXCEPTIONS
    {
        const optional<X> opt;
        try
        {
            (void)opt.value();
            assert(false);
        }
        catch (const bad_optional_access&)
        {
        }
    }
#endif
}
开发者ID:lichray,项目名称:libcxx,代码行数:29,代码来源:value_const.pass.cpp


示例5: test_function_value_for

void test_function_value_for()
{
  optional<T> o0;
  optional<T> o1(1);
  const optional<T> oC(2);
  
  try
  {
    T& v = o1.value();
    BOOST_TEST(v == 1);
  }
  catch(...)
  {
    BOOST_TEST(false);
  }
  
  try
  {
    T const& v = oC.value();
    BOOST_TEST(v == 2);
  }
  catch(...)
  {
    BOOST_TEST(false);
  }
  
  BOOST_TEST_THROWS(o0.value(), boost::bad_optional_access);
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:28,代码来源:optional_test_old_impl.cpp


示例6:

void
ThreadedLoader::load_graph(bool                       merge,
                           const Glib::ustring&       document_uri,
                           optional<Raul::Path>       engine_parent,
                           optional<Raul::Symbol>     engine_symbol,
                           optional<Node::Properties> engine_data)
{
	_mutex.lock();

	Ingen::World* world = _app.world();

	Glib::ustring engine_base = "";
	if (engine_parent) {
		if (merge)
			engine_base = engine_parent.get();
		else
			engine_base = engine_parent.get().base();
	}

	_events.push_back(
		sigc::hide_return(
			sigc::bind(sigc::mem_fun(world->parser().get(),
			                         &Ingen::Serialisation::Parser::parse_file),
			           _app.world(),
			           _app.world()->interface().get(),
			           document_uri,
			           engine_parent,
			           engine_symbol,
			           engine_data)));

	_mutex.unlock();
	_sem.post();
}
开发者ID:EQ4,项目名称:lad,代码行数:33,代码来源:ThreadedLoader.cpp


示例7: TEST

TEST(Optional, Constexpr)
{
	constexpr auto string = "abcdefgh";
	constexpr optional<int> a{32};
	constexpr optional<decltype(string)> b{string};
	constexpr optional<float> c{3.14f};
	constexpr optional<int> d{};
	
	EXPECT_THAT(*a, Eq(32));
	EXPECT_THAT(*b, Eq(string));
	EXPECT_THAT(*c, FloatEq(3.14f));
	EXPECT_FALSE(d);
	
	constexpr int i = *a;
	constexpr int j = a.value();
	
	EXPECT_THAT(i, Eq(*a));
	EXPECT_THAT(j, Eq(*a));
	
	struct Literal { };
	
	static_assert(std::is_literal_type<optional<int>>::value, "Type error");
	static_assert(std::is_literal_type<optional<float>>::value, "Type error");
	static_assert(std::is_literal_type<optional<Literal>>::value, "Type error");
}
开发者ID:mknejp,项目名称:xtd,代码行数:25,代码来源:optional.cpp


示例8: get_abi_serializer

static const abi_serializer& get_abi_serializer() {
   static optional<abi_serializer> _abi_serializer;
   if (!_abi_serializer) {
      _abi_serializer.emplace(eosio_contract_abi(abi_def()));
   }

   return *_abi_serializer;
}
开发者ID:wood19910377,项目名称:eos,代码行数:8,代码来源:eosio_contract.cpp


示例9: mergeAndOverride

void
CachePolicy::mergeAndOverride(const optional<CachePolicy>& rhs)
{
    if ( rhs.isSet() )
    {
        mergeAndOverride( rhs.get() );
    }
}
开发者ID:3dcl,项目名称:osgearth,代码行数:8,代码来源:CachePolicy.cpp


示例10: if

	bool operator==( const optional<T>& left, const optional<T>& right ) {
		if ( left && right ) {
			return left.value( ) == right.value( );
		}
		else if ( !left && !right ) {
			return true;
		}
		return false;
	}
开发者ID:CCJY,项目名称:coliru,代码行数:9,代码来源:main.cpp


示例11: return

 bool const operator==(optional const & other) const {
     if (!valid() && !other.valid()) {
         return true;
     }
     
     if (valid() ^ other.valid()) {
         return false;
     }
     
     return ((**this) == (*other));
 }
开发者ID:ggervais,项目名称:cpp-game-engine,代码行数:11,代码来源:optional.hpp


示例12: Source_location

 Source_location(
     string              filename,
     optional<int>       linenumber          = {},
     optional<int>       character_position  = {},
     optional<string>    function_name       = {}
     ):
     m_filename{ move( filename ) },
     m_linenumber{ linenumber.value_or( -1 ) },
     m_character_position{ character_position.value_or( -1 ) },
     m_function_name{ move( function_name ).value_or( "" ) }
 {}
开发者ID:alf-p-steinbach,项目名称:cppx,代码行数:11,代码来源:Source_location.hpp


示例13: VerifyCommandHandling

	// Вспомогательная функция для проверки работы команды command
	// Она принимает ожидаемый номер канала expectedChannel и expectedOutput
	void VerifyCommandHandling(const string& command, const optional<int> & expectedChannel, const string& expectedOutput)
	{
		// Предварительно очищаем содержимое выходного потока
		output = stringstream();
		input = stringstream();
		BOOST_CHECK(input << command);
		BOOST_CHECK(remoteControl.HandleCommand());
		BOOST_CHECK_EQUAL(tv.IsTurnedOn(), expectedChannel.is_initialized());
		BOOST_CHECK_EQUAL(tv.GetChannel(), expectedChannel.get_value_or(0));
		BOOST_CHECK(input.eof());
		BOOST_CHECK_EQUAL(output.str(), expectedOutput);
	}
开发者ID:alexey-malov,项目名称:oop,代码行数:14,代码来源:RemoteControlTests.cpp


示例14: affect

    static void affect( value& v, optional< T > const& opt )
    {
      if( opt.is_none() )
	{
	  v = Val_int( 0 );
	}
      else
	{
	  v = caml_alloc_tuple(1);
	  field_affectation_management< T >::affect_field(v, 0, opt.get_value() );
	}
    }
开发者ID:Elarnon,项目名称:Ocsfml,代码行数:12,代码来源:type_option.hpp


示例15: swap

		void swap(optional& other) {
			if (other.valid() && valid()) {
				swap(**this, *other);
			}
			else if (!other.valid() && !valid()) {
				return;
			}
			optional& source = other ? *this : other;
			optional& target = other ? other : *this;
			target.unchecked_place(std::move(*source));
			source.unchecked_destroy();
		}
开发者ID:daviddhas,项目名称:CS-gO,代码行数:12,代码来源:optional.hpp


示例16: test_function_value_or_for

void test_function_value_or_for()
{
  optional<T> oM0;
  const optional<T> oC0;
  optional<T> oM1(1);
  const optional<T> oC2(2);
  
  BOOST_TEST(oM0.value_or(5) == 5);
  BOOST_TEST(oC0.value_or(5) == 5);
  BOOST_TEST(oM1.value_or(5) == 1);
  BOOST_TEST(oC2.value_or(5) == 2);
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:12,代码来源:optional_test_old_impl.cpp


示例17: createMetadata

void IndexSync::createMetadata(const optional<string>& keyPath, const bool unique)
	{
	this->keyPath = keyPath;
	this->unique = unique;

	auto_ptr<Implementation::Transaction> transaction = transactionFactory.createTransaction();

	metadata.putMetadata("unique", Data(&unique, sizeof(bool), Data::Boolean), true, *transaction);
	metadata.putMetadata("keyPath", keyPath.is_initialized() ? Data(keyPath.get()) : Data::getUndefinedData(), true, *transaction);
	
	transaction->commit();
	}
开发者ID:gwobay,项目名称:indexeddb,代码行数:12,代码来源:IndexSync.cpp


示例18:

bool
operator==(
	optional<T> const &_a,
	optional<T> const &_b
)
{
	return
		_a && _b
		?
			*_a == *_b
		:
			_a.has_value() == _b.has_value();
}
开发者ID:pmiddend,项目名称:sgedoxy,代码行数:13,代码来源:optional_comparison.hpp


示例19:

	bool const operator < (optional const & other) const
	{
		// equally invalid - not smaller.
		if ((! valid()) && (! other.valid()))   { return false; }

		// I'm not valid, other must be, smaller.
		if (! valid())	{ return true; }

		// I'm valid, other is not valid, I'm larger
		if (! other.valid()) { return false; }

		return ((* * this) < (* other));
	}
开发者ID:Ostkaka,项目名称:ANT,代码行数:13,代码来源:templates.hpp


示例20: addBullet

void SpacePage::addBullet(Vector pos, Vector dir, PlayerID owner)
{
    static optional<Gosu::Sample> s_Sample;
    if (!s_Sample) {
        s_Sample.reset(Gosu::Sample(L"sfx/phaser1.wav"));
    }
    s_Sample->play();
    Bullet b;
    b.pos = pos;
    b.dir = dir.normalized()*10;
    b.lifetime = 0;
    b.owner = owner;
    m_Bullets.push_back(b);
}
开发者ID:oli-obk,项目名称:lightshifters,代码行数:14,代码来源:space_page.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ optional_device类代码示例发布时间:2022-05-31
下一篇:
C++ opstream类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap