$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r71785 - sandbox/coerce/libs/coerce/example
From: vexocide_at_[hidden]
Date: 2011-05-07 13:58:42
Author: vexocide
Date: 2011-05-07 13:58:41 EDT (Sat, 07 May 2011)
New Revision: 71785
URL: http://svn.boost.org/trac/boost/changeset/71785
Log:
Added an example implementing a std::strtol backend
Added:
   sandbox/coerce/libs/coerce/example/backend.cpp   (contents, props changed)
Added: sandbox/coerce/libs/coerce/example/backend.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/example/backend.cpp	2011-05-07 13:58:41 EDT (Sat, 07 May 2011)
@@ -0,0 +1,37 @@
+//              Copyright Jeroen Habraken 2011.
+//
+// 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)
+
+#include <boost/coerce.hpp>
+
+#include <cerrno>  // for errno
+#include <cstdio>  // for std::strtol
+#include <iostream>
+
+struct strtol {
+    template <typename Target, typename Source>
+    static inline bool
+    call(Target & target, Source const & source) {
+        target = std::strtol(source, NULL, 10);
+
+        return (errno != EINVAL);
+    }
+};
+
+namespace boost { namespace coerce { namespace traits {
+
+    template <std::size_t N>
+    struct as<long int, char [N]>
+        : strtol { };
+
+} } }  // namespace boost::coerce::traits
+
+int
+main() {
+    using namespace boost;
+
+    // A coerce from char [N] to long int using std::strtol
+    std::cout << coerce::as<long int>("23") << std::endl;
+}