Skip to content

Commit

Permalink
Add support for bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Elyas El Idrissi committed Apr 6, 2023
1 parent 334ff8d commit be9362f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/soci/bool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (C) 2023 Elyas El Idrissi
// 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)
//

#ifndef SOCI_BOOL_H_INCLUDED
#define SOCI_BOOL_H_INCLUDED

#include "soci/type-conversion-traits.h"

namespace soci
{

// simple fall-back for bool
template <>
struct type_conversion<bool>
{
typedef short base_type;

static void from_base(base_type in, indicator ind, bool & out)
{
out = ind != i_null ? static_cast<bool>(in) : false;
}

static void to_base(bool in, base_type & out, indicator & ind)
{
out = static_cast<base_type>(in);
ind = i_ok;
}
};

} // namespace soci

#endif // SOCI_BOOL_H_INCLUDED

0 comments on commit be9362f

Please sign in to comment.