From 513d9362c96e17647ba8ca1ce7e329a7df9acdfc Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Thu, 8 Dec 2016 17:01:32 +0100 Subject: [PATCH] #5 value accepting any arithmetic type --- include/cpp-json/value.h | 8 +++----- include/cpp-json/value.tcc | 26 +++----------------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/include/cpp-json/value.h b/include/cpp-json/value.h index de1e108..3040105 100644 --- a/include/cpp-json/value.h +++ b/include/cpp-json/value.h @@ -48,11 +48,9 @@ class value { value(const char *s); value(const object &o); value(std::string s); - value(double x); - value(float x); - value(int x); - value(long x); - value(const std::nullptr_t &); + template>> + value(T n); + value(const std::nullptr_t &); public: value(); diff --git a/include/cpp-json/value.tcc b/include/cpp-json/value.tcc index 8726018..1596eab 100644 --- a/include/cpp-json/value.tcc +++ b/include/cpp-json/value.tcc @@ -73,29 +73,9 @@ inline value::value(std::string s) : type_(type_string) { //------------------------------------------------------------------------------ // Name: value //------------------------------------------------------------------------------ -inline value::value(double x) : type_(type_number) { - new (&value_) std::string(std::to_string(x)); -} - -//------------------------------------------------------------------------------ -// Name: value -//------------------------------------------------------------------------------ -inline value::value(float x) : type_(type_number) { - new (&value_) std::string(std::to_string(x)); -} - -//------------------------------------------------------------------------------ -// Name: value -//------------------------------------------------------------------------------ -inline value::value(long x) : type_(type_number) { - new (&value_) std::string(std::to_string(x)); -} - -//------------------------------------------------------------------------------ -// Name: value -//------------------------------------------------------------------------------ -inline value::value(int x) : type_(type_number) { - new (&value_) std::string(std::to_string(x)); +template +value::value(T n) : type_(type_number) { + new (&value_) std::string(std::to_string(x)); } //------------------------------------------------------------------------------