本文整理匯總了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;
}
示例2: swap
void Callback::swap( Callback& rhs ) {
using std::swap;
swap( m_id, rhs.m_id );
swap( m_callback, rhs.m_callback );
}
示例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_);
}
示例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.
//.........這裏部分代碼省略.........
示例5: func11
double func11(double x) {
++iteration_count;
return sin(0.01 / x) - 0.01;
};
示例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);
//.........這裏部分代碼省略.........
示例7: HasPtr
HasPtr(const string &s = string()):
ps(new string(s)), i(0) { }
示例8: chomp_carriage_return
void chomp_carriage_return(char* str) {
int len = strlen(str);
if ( str[len-1] == '\r' )
str[len-1] = '\0';
}
示例9: func8
double func8(double x) {
++iteration_count;
return exp(21000.0 / x) / (1.11e11 * x * x) - 1.0;
};
示例10: func9
double func9(double x) {
++iteration_count;
return 1.0 / x + log(x) - 100.0;
};
示例11: func6
double func6(double x) {
++iteration_count;
return 1e10 * pow(x, 1.0 / x) - 1.0;
};
示例12: func7
double func7(double x) {
++iteration_count;
return pow(x, 20.0) - 1.0;
};
示例13: func4
double func4(double x) {
++iteration_count;
return exp(1.0 / x - 25.0) - 1.0;
};
示例14: func3
double func3(double x) {
++iteration_count;
return 2.0 * x * exp(-20.0) + 1.0 - 2.0 * exp(-20.0 * x);
};
示例15: func1
double func1(double x) {
++iteration_count;
return 4.0 * cos(x) - exp(x);
};