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


C++ std类代码示例

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


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

示例1: swap

 stacktrace& operator=(stacktrace other)
 {
     using std::swap;
     swap(call_stack_, other.call_stack_);
     return *this;
 }
开发者ID:jarmond,项目名称:prime-cpp,代码行数:6,代码来源:stacktrace.hpp

示例2: swap

			void Callback::swap( Callback& rhs ) {
				using std::swap;
				swap( m_id, rhs.m_id );
				swap( m_callback, rhs.m_callback );
			}
开发者ID:xeroskiller,项目名称:nodepp,代码行数:5,代码来源:base_callback.cpp

示例3: swap

	friend void swap(ResourceHandle<Handle>& a, ResourceHandle<Handle>& b) noexcept
	{
		using std::swap;
		swap(static_cast<Resource&>(a), static_cast<Resource&>(b));
		swap(a.handle_, b.handle_);
	}
开发者ID:nyorain,项目名称:vpp,代码行数:6,代码来源:resource.hpp

示例4: main

int main ()
{
  std::cout << "Nonfinite_num_facet very simple example." << std::endl;

  if((std::numeric_limits<double>::has_infinity == 0) || (std::numeric_limits<double>::infinity() == 0))
  {
    std::cout << "Infinity not supported on this platform." << std::endl;
    return 0;
  }

  if((std::numeric_limits<double>::has_quiet_NaN == 0) || (std::numeric_limits<double>::quiet_NaN() == 0))
  {
    std::cout << "NaN not supported on this platform." << std::endl;
    return 0;
  }

  std::locale default_locale (std::locale::classic ()); // Note the currrent (default C) locale.

  // Create plus and minus infinity.
  double plus_infinity = +std::numeric_limits<double>::infinity();
  double minus_infinity = -std::numeric_limits<double>::infinity();

  // and create a NaN (NotANumber)
  double NaN = +std::numeric_limits<double>::quiet_NaN ();

  double negated_NaN = (boost::math::changesign)(std::numeric_limits<double>::quiet_NaN ());


  // Output the nonfinite values using the current (default C) locale.
  // The default representations differ from system to system,
  // for example, using Microsoft compilers, 1.#INF, -1.#INF, and 1.#QNAN.
  cout << "Using C locale" << endl;
  cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl;
  cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl;
  cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl;

  // Display negated NaN.
  cout << "negated NaN " << negated_NaN << endl; // "-1.IND"
  
  // Create a new output locale, and add the nonfinite_num_put facet
  std::locale C99_out_locale (default_locale, new boost::math::nonfinite_num_put<char>);
  // and imbue the cout stream with the new locale.
  cout.imbue (C99_out_locale);

  // Or for the same effect more concisely:
  cout.imbue (locale(locale(), new boost::math::nonfinite_num_put<char>));

  // Output using the new locale
  cout << "Using C99_out_locale " << endl;
  cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl;
  cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl;
  cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl;

  // Display negated NaN.
  cout << "negated NaN " << negated_NaN << endl; // -nan

  // Create a string with the expected C99 representation of plus infinity.
  std::string inf = "inf";
  { // Try to read an infinity value using the default C locale.
    // Create an input stream which will provide "inf"
    std::istringstream iss (inf);

     // Create a double ready to take the input,
    double infinity;
    // and read "inf" from the stringstream:
    iss >> infinity; 

    // This will not work on all platforms!
    if (! iss)
    { // Reading infinity went wrong!
      std::cerr << "C locale input format error!" << std::endl;
    }
  } // Using default C locale.

  { // Now retry using C99 facets.
  // Create a new input locale and add the nonfinite_num_get facet.
  std::locale C99_in_locale (default_locale, new boost::math::nonfinite_num_get<char>);

  // Create an input stream which will provide "inf".
  std::istringstream iss (inf);
  // Imbue the stream with the C99 input locale.
  iss.imbue (C99_in_locale);

  // Create a double ready to take the input,
  double infinity;
  // and read from the stringstream:
  iss >> infinity; 

  if (! iss)
  { // Reading infinity went wrong!
    std::cout << "C99 input format error!" << std::endl;
  }
  // Expect to get an infinity, which will display still using the C99 locale as "inf"
  cout << "infinity in C99 representation is " << infinity << endl; 

  // To check, we can switch back to the default C locale.
  cout.imbue (default_locale);
  cout <<  "infinity in default C representation is " << infinity << endl; 
  } // using C99 locale.

//.........这里部分代码省略.........
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:101,代码来源:nonfinite_facet_simple.cpp

示例5: func11

double func11(double x) {
  ++iteration_count;
  return sin(0.01 / x) - 0.01;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例6: initBox2DTypeBindings

void initBox2DTypeBindings(GameManager& game) {
    LuaContext& lua = *game.getLuaContext();

    lua.writeVariable("Box2D", LuaEmptyArray);
    {
        lua.writeVariable("Box2D", "Vector", LuaEmptyArray);
        {
            lua.writeFunction("Box2D", "Vector", "new",
            [](const optional<float>& arg1, const optional<float>& arg2) {
                if (arg1 && arg2) {
                    // If the scripter passed in two arguments...
                    return b2Vec2(*arg1, *arg2);
                }
                else if (!(arg1 || arg2)) {
                    // Else if the scripter passed in *no* arguments...
                    return b2Vec2(0, 0);
                }
                else {
                    throw invalid_argument(
                        "Must pass in two numbers or nothing at all"
                    );
                }

            });
            lua.registerMember("x", &b2Vec2::x);
            lua.registerMember("y", &b2Vec2::y);
        }

        lua.writeVariable("Box2D", "BodyType", LuaEmptyArray);
        {
            lua.writeVariable("Box2D", "BodyType", "Static", b2_staticBody);
            lua.writeVariable("Box2D", "BodyType", "Dynamic", b2_dynamicBody);
            lua.writeVariable("Box2D", "BodyType", "Kinematic", b2_kinematicBody);
        }

        lua.writeVariable("Box2D", "BodyDef", LuaEmptyArray);
        {
            lua.writeFunction("Box2D", "BodyDef", "new", getDefaultConstructorLambda<b2BodyDef>());

            lua.registerMember("active", &b2BodyDef::active);
            lua.registerMember("allowSleep", &b2BodyDef::allowSleep);
            lua.registerMember("angle", &b2BodyDef::angle);
            lua.registerMember("angularDamping", &b2BodyDef::angularDamping);
            lua.registerMember("angularVelocity", &b2BodyDef::angularVelocity);
            lua.registerMember("awake", &b2BodyDef::awake);
            lua.registerMember("bullet", &b2BodyDef::bullet);
            lua.registerMember("fixedRotation", &b2BodyDef::fixedRotation);
            lua.registerMember("gravityScale", &b2BodyDef::gravityScale);
            lua.registerMember("linearDamping", &b2BodyDef::linearDamping);
            lua.registerMember("linearVelocity", &b2BodyDef::linearVelocity);
            lua.registerMember("position", &b2BodyDef::position);
            lua.registerMember("type", &b2BodyDef::type);
        }

        lua.writeVariable("Box2D", "Body", LuaEmptyArray);
        {
            lua.writeFunction("Box2D", "Body", "new", [&game](const b2BodyDef& def) {
                return game.getPhysicsWorld()->CreateBody(&def);
            });
            lua.registerMember<b2Body, bool>("awake",
            [](const b2Body& object) {
                return object.IsAwake();
            },
            [](b2Body& object, const bool val) {
                object.SetAwake(val);
            });
            lua.registerMember<b2Body, bool>("fixedRotation",
            [](const b2Body& object) {
                return object.IsFixedRotation();
            },
            [](b2Body& object, const bool val) {
                object.SetFixedRotation(val);
            });
            lua.registerMember<b2Body, b2Vec2>("position",
            [](const b2Body& body) {
                return body.GetPosition();
            },
            [](b2Body& body, const b2Vec2& pos) {
                body.SetTransform(pos, body.GetAngle());
            });
            lua.registerFunction<b2Body, b2Fixture*(b2FixtureDef&)>("CreateFixture",
            [](b2Body& body, b2FixtureDef& def) {
                return body.CreateFixture(&def);
            });
        }

        lua.writeVariable("Box2D", "Filter", LuaEmptyArray);
        {
            lua.writeFunction("Box2D", "Filter", "new", getDefaultConstructorLambda<b2Filter>());
            lua.registerMember("categoryBits", &b2Filter::categoryBits);
            lua.registerMember("maskBits", &b2Filter::maskBits);
            lua.registerMember("groupIndex", &b2Filter::groupIndex);
        }

        lua.writeVariable("Box2D", "FixtureDef", LuaEmptyArray);
        {
            lua.writeFunction("Box2D", "FixtureDef", "new", getDefaultConstructorLambda<b2FixtureDef>());
            lua.registerMember("friction", &b2FixtureDef::friction);
            lua.registerMember("restitution", &b2FixtureDef::restitution);
            lua.registerMember("density", &b2FixtureDef::density);
//.........这里部分代码省略.........
开发者ID:JesseTG,项目名称:RAY,代码行数:101,代码来源:box2d_type_bindings.cpp

示例7: HasPtr

 HasPtr(const string &s = string()):
     ps(new string(s)), i(0) { }
开发者ID:qinf,项目名称:cpp_primer,代码行数:2,代码来源:13.11.cpp

示例8: chomp_carriage_return

void chomp_carriage_return(char* str) {
    int len = strlen(str);
    if ( str[len-1] == '\r' )
        str[len-1] = '\0';
}
开发者ID:glycerine,项目名称:shore-mt,代码行数:5,代码来源:chomp.cpp

示例9: func8

double func8(double x) {
  ++iteration_count;
  return exp(21000.0 / x) / (1.11e11 * x * x) - 1.0;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例10: func9

double func9(double x) {
  ++iteration_count;
  return 1.0 / x + log(x) - 100.0;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例11: func6

double func6(double x) {
  ++iteration_count;
  return 1e10 * pow(x, 1.0 / x) - 1.0;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例12: func7

double func7(double x) {
  ++iteration_count;
  return pow(x, 20.0) - 1.0;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例13: func4

double func4(double x) {
  ++iteration_count;
  return exp(1.0 / x - 25.0) - 1.0;
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例14: func3

double func3(double x) {
  ++iteration_count;
  return 2.0 * x * exp(-20.0) + 1.0 - 2.0 * exp(-20.0 * x);
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp

示例15: func1

double func1(double x) {
  ++iteration_count;
  return 4.0 * cos(x) - exp(x);
};
开发者ID:ahmadyan,项目名称:ReaK,代码行数:4,代码来源:test_root_finders_perf.cpp


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