Skip to content

Commit

Permalink
fixup! Wrappers: Use wrapper factory to construct Python wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
vawale committed Jun 27, 2024
1 parent e5cb5c7 commit a476db9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/include/ZividPython/Releasable.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <ZividPython/Traits.h>

#include <cstddef>
#include <memory>
#include <optional>
#include <pybind11/pybind11.h>
Expand Down Expand Up @@ -129,7 +132,8 @@ namespace ZividPython
class Singleton
{
public:
template<typename... Args>
template<typename... Args,
typename std::enable_if<!has_type<Singleton<T>, Args...>::value, void *>::type = nullptr>
Singleton(Args &&...args)
{
// Keep the singleton alive forever to avoid races with
Expand Down
14 changes: 14 additions & 0 deletions src/include/ZividPython/Traits.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <type_traits>
#include <tuple>

#if __has_include(<experimental/type_traits>)
# include <experimental/type_traits>
Expand Down Expand Up @@ -42,4 +43,17 @@ namespace ZividPython
template<template<class...> class Op, class... Args>
using is_detected = typename Detail::detector<Detail::nonesuch, void, Op, Args...>::value_t;
#endif


template<typename T, typename... Ts>
struct has_type;

template<typename T, typename... Ts>
struct has_type<T, std::tuple<Ts...>> : std::disjunction<std::is_same<T, Ts>...>
{};

template<typename T, typename First, typename... Rest>
struct has_type<T, First, Rest...> : has_type<T, std::tuple<First, Rest...>>
{};

} // namespace ZividPython

0 comments on commit a476db9

Please sign in to comment.