1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//
// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_STD_OPTIONAL_H_INCLUDED
#define SOCI_STD_OPTIONAL_H_INCLUDED
#include "soci/type-conversion-traits.h"
#include <optional>
namespace soci
{
// simple fall-back for std::optional
template <typename T>
struct type_conversion<std::optional<T> >
{
typedef typename type_conversion<T>::base_type base_type;
static void from_base(base_type const & in, indicator ind,
std::optional<T> & out)
{
if (ind == i_null)
{
out.reset();
}
else
{
T tmp = T();
type_conversion<T>::from_base(in, ind, tmp);
out = tmp;
}
}
static void to_base(std::optional<T> const & in,
base_type & out, indicator & ind)
{
if (in)
{
type_conversion<T>::to_base(*in, out, ind);
}
else
{
ind = i_null;
}
}
};
} // namespace soci
#endif // SOCI_STD_OPTIONAL_H_INCLUDED
|