Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements type trait is_truth_table #53

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ v0.5 (not yet released)
* Cube methods: ``difference`` (contributed by Heinz Riener)
`#52 <https://github.com/msoeken/kitty/pull/52>`_

* Type traits: ``is_truth_table``
`#53 <https://github.com/msoeken/kitty/pull/53>`_

v0.4 (May 4, 2018)
------------------

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Welcome to kitty's documentation!
esop
isop
cnf
traits
reference

Indices and tables
Expand Down
7 changes: 7 additions & 0 deletions docs/traits.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Type traits
===========

A type trait ``is_truth_table<T>`` can be used to check whether type ``T``
implements a truth table type. The value ``is_truth_table<T>::value``
evaluates to true if ``T`` is ``dynamic_truth_table`` or
``static_truth_table<NumVars>`` (for any ``NumVars``), and ``false``, otherwise.
1 change: 1 addition & 0 deletions include/kitty/kitty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "print.hpp"
#include "properties.hpp"
#include "spectral.hpp"
#include "traits.hpp"

/*
/\___/\
Expand Down
49 changes: 49 additions & 0 deletions include/kitty/traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* kitty: C++ truth table library
* Copyright (C) 2017-2018 EPFL
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

/*!
\file traits.hpp
\brief Type traits for truth tables

\author Mathias Soeken
*/

#pragma once

#include <type_traits>

namespace kitty
{

template<class TT>
struct is_truth_table : std::false_type {};

template<>
struct is_truth_table<kitty::dynamic_truth_table> : std::true_type {};

template<int NumVars>
struct is_truth_table<kitty::static_truth_table<NumVars>> : std::true_type {};

}
43 changes: 43 additions & 0 deletions test/traits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* kitty: C++ truth table library
* Copyright (C) 2017-2018 EPFL
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include <gtest/gtest.h>

#include <kitty/dynamic_truth_table.hpp>
#include <kitty/static_truth_table.hpp>
#include <kitty/traits.hpp>

using namespace kitty;

TEST( TraitsTest, supports_traits )
{

EXPECT_TRUE( is_truth_table<dynamic_truth_table>::value );
EXPECT_TRUE( is_truth_table<static_truth_table<4>>::value );
EXPECT_TRUE( is_truth_table<static_truth_table<5>>::value );
EXPECT_TRUE( is_truth_table<static_truth_table<6>>::value );
EXPECT_FALSE( is_truth_table<uint64_t>::value );

}