MSVC support

This commit is contained in:
Daniel Sipka 2015-09-24 11:43:27 +02:00
parent bce9d570ba
commit 87912c46db
5 changed files with 15 additions and 8 deletions

View File

@ -1,7 +1,13 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
project(mstch) project(mstch)
option (WITH_UNIT_TESTS "enable building unit test executable" OFF) option (WITH_UNIT_TESTS "enable building unit test executable" OFF)
set(CMAKE_BUILD_TYPE Release)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O3")
endif()
add_subdirectory(src) add_subdirectory(src)
if(WITH_UNIT_TESTS) if(WITH_UNIT_TESTS)
enable_testing() enable_testing()

View File

@ -4,6 +4,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <memory> #include <memory>
#include <functional>
#include <boost/variant.hpp> #include <boost/variant.hpp>
@ -20,7 +21,7 @@ class object_t {
} }
bool has(const std::string name) const { bool has(const std::string name) const {
return methods.count(name); return methods.count(name) != 0;
} }
protected: protected:

View File

@ -25,7 +25,7 @@ std::string render_context::push::render(const template_type& templt) {
render_context::render_context( render_context::render_context(
const mstch::node& node, const mstch::node& node,
const std::map<std::string, template_type>& partials): const std::map<std::string, template_type>& partials):
partials{partials}, nodes{node} partials(partials), nodes(1, node)
{ {
state.push(std::unique_ptr<render_state>(new outside_section)); state.push(std::unique_ptr<render_state>(new outside_section));
} }

View File

@ -23,7 +23,7 @@ void template_type::tokenize(const std::string& tmp) {
citer beg = tmp.begin(); citer beg = tmp.begin();
auto npos = std::string::npos; auto npos = std::string::npos;
for (unsigned long cur_pos = 0; cur_pos < tmp.size();) { for (unsigned long long cur_pos = 0; cur_pos < tmp.size();) {
auto open_pos = tmp.find(open, cur_pos); auto open_pos = tmp.find(open, cur_pos);
auto close_pos = tmp.find( auto close_pos = tmp.find(
close, open_pos == npos ? open_pos : open_pos + 1); close, open_pos == npos ? open_pos : open_pos + 1);

View File

@ -3,9 +3,9 @@
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
unsigned long current_msec() { unsigned long long current_msec() {
return std::chrono::system_clock::now().time_since_epoch() / return std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::milliseconds(1); std::chrono::system_clock::now()).time_since_epoch().count();
} }
int main() { int main() {
@ -25,7 +25,7 @@ int main() {
}} }}
}; };
std::vector<unsigned long> times; std::vector<unsigned long long> times;
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
auto start = current_msec(); auto start = current_msec();
for (int i = 0; i < 5000; i++) for (int i = 0; i < 5000; i++)