Code Monkey home page Code Monkey logo

algorithms-dstructure's Introduction

Algorithms-Dstructure(C++语言描述,具备C++特性)

以下列举一些常见实用特性,更多完整特性请参阅官方文档MSDN

Initialize List(初始化列表)

  • STL容器的初始化列表:
//所有STL容器都支持,限于篇幅举例说明
std::vector<double> i_v = {1.1, 2.2, 3.3};
std::map<int, std::string> m = {{1, "a"}, {2, "b"}};
  • 自定义类的初始化列表:
class A
{
public:
    A(const int item, const string nameItem):length(item), name(nameItem)
private:
    int length;
    string name;
};
//实例化对象
A a1(3, "Hamlet");

类型推导 Auto Type

  • 类型声明方面
//过去的这种冗长的类型声明
std::map<int, std::string>::const_iterator itr = m.find(1);
//现在可以写成这样了
auto itr = m.find(1);

//编译器会自动推导出正确的类型。字面量也可以:
auto i = 1;          // int
auto d = 1.1;        // double
auto s = "hi";       // const char*
auto a = { 1, 2 };   // std:: initializer_list<int>
  • 泛型编程方面
template<typename T, typename K>
auto add(T a, K b) {
    return a + b;
}

auto a = add(1, 2);     // int add(int, int) a -> int
auto b = add(1, 2.2);   // double add(int, double) b -> double
//注:留意第二个调用,返回值被正确地推断为double类型。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.