[ create a new paste ] login | about

Link: http://codepad.org/9JhV7Fuu    [ raw code | output | fork ]

C++, pasted on Sep 30:
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>

namespace Json {
template <typename ValueType>
struct Value {
	Value() {}
	Value(int) {}
	Value(float) {}
	Value(unsigned int) {}
	Value(std::string) {}
};
}

template <typename T>
Json::Value<T> toJson(T x) {
	return Json::Value<T>(x);
}

template <typename T, typename U>
Json::Value< std::pair<T, U> > toJson(std::pair<T, U> const& rh) {
	Json::Value< std::pair<T, U> > return_value;
	toJson(rh.first);
	toJson(rh.second);
	return return_value;
}

template <typename T>
Json::Value<T> toJsonContainer(T const& rh) {
	Json::Value<T> return_value;
	
	for (auto& e : rh) {
		toJson(e);
	}

	return return_value;
}

template <typename T, typename U>
Json::Value< std::map<T, U> > toJson(std::map<T, U> const& rh) {
	return toJsonContainer(rh);
}

template <typename T>
Json::Value< std::vector<T> > toJson(std::vector<T> const& rh) {
	return toJsonContainer(rh);
}

int main(int argc, char **argv) {
	std::map<std::string, std::vector<unsigned int>> x;
	toJson(x);
	
	return 0;
}


Output:
1
2
3
In function 'Json::Value<T> toJsonContainer(const T&)':
Line 35: error: a function-definition is not allowed here before ':' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: