Skip to content

Instantly share code, notes, and snippets.

// Example program
#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <memory>
#include <functional>
void foo(int argc, const char* argv[]) {
while (argc--)
std::cout << *argv++ << ' ';
}
int main()
{
std::vector<std::string> vec {"1", "2", "3", "4"};
std::vector<const char*> vecptr;
std::transform(std::begin(vec), std::end(vec), std::back_inserter(vecptr),
#include <iostream>
class Base {
public:
virtual void DoCall() { std::cout << "base docall" << std::endl; }
void Display() { DoCall(); }
};
class Derived : public Base {
public:
#include <vector>
#include <iostream>
static int gCounter = 0;
class Foo {
public:
Foo(int n = 0)
:pval_(new int(n)) {
index_ = gCounter++;
}
CC = g++
BINDIR = ./bin
CFLAGS = -c -g -O0 -std=c++11 -I../include
LDFLAGS =
SOURCES = $(wildcard *.cc)
OBJECTS = $(SOURCES:.cc=.o)
FAKEOBJECTS = $(OBJECTS)
EXECUTABLE = $(addprefix $(BINDIR)/, $(basename $(SOURCES:.cpp=)))
.PHONY: all

使用STL算法的好处在于,写得熟练的情况下可以快速写出正确的代码,手写循环总有几率忽略边界情况导致出错而且编码速度比较慢。STL算法的缺陷在于数量比较少也不够灵活,有时不能以最高的效率完成算法逻辑。下面这个代码虽然效率差了点,作为原型使用还是挺不错的.

// https://leetcode.com/problems/valid-palindrome/
class Solution {
 public:
  bool isPalindrome(string s) {
    s.erase(std::remove_if(std::begin(s), std::end(s), [](char ch) {
      return !isalnum(ch);
    }), std::end(s));
 return std::equal(
! function() {
function t(t, n) {
function i(t) {
var e, n = null;
try {
e = t.createRequest(), e ? t.sendRequest(e) || (n = r("sendRequest failed.", e, t.getVersion(), t.getVersionParamName(), t.at_script)) : n = r("createRequest failed.", e, t.getVersion(), t.getVersionParamName(), t.at_script)
} catch (i) {
n = r(i.name + ": " + i.message, e, t.getVersion(), t.getVersionParamName(), t ? t.at_script : null, i)
}
return n
//
// async_client.cpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
//
// async_client.cpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@theidexisted
theidexisted / cmakelists.txt
Created January 27, 2016 08:59
for proxygen build
project(echo_server CXX)
cmake_minimum_required(VERSION 2.8)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g -O0 -Wall -std=c++11")
set(CMAKE_CXX_FLAGS "-O2 -Wall -std=c++11")
add_executable(echo_server
${SRC_FILES}
)