boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.14k stars 138 forks source link

Adding default Destructor breaks Compilation #428

Closed heilkn closed 4 years ago

heilkn commented 5 years ago

Hello, thank you for your work on this promising and interesting library. As I have already mentioned in another thread I am evaluating and exploring this library a little bit.

For the following code uncommenting the default destructor for vulkan::Instance breaks compilation with the error attached at the bottom of this message.

#include <DI/di.hpp>
namespace di = boost::di;

#include <iostream>
#include <tuple>

#pragma once

#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <vulkan/vulkan.hpp>

#include <iostream>
#include <optional>
#include <vector>

struct AppName { char const* name; };

namespace glfw {
    class Instance {
    public:
        Instance();

    private:
        std::shared_ptr<nullptr_t> _deleter;
    };

    class Window {
    public:
        struct Height { int h; };
        struct Width { int w; };

        Window(Instance const& instance, AppName const& appName, Height h, Width w);
        Window(GLFWwindow* window);

        operator GLFWwindow& ();
        operator GLFWwindow const&() const;
        GLFWwindow& operator* ();
        GLFWwindow const& operator*() const;

    private:
        std::shared_ptr<GLFWwindow> _window;
    };
}

namespace vulkan {
    struct DebuggingLayersFlag {
        const bool enable;
    };

    template <typename Type>
    using Handle = vk::UniqueHandle<Type, vk::DispatchLoaderStatic>;

    class ValidationLayers {
    public:
        using NamesList = std::vector<char const*> const;
        ValidationLayers(DebuggingLayersFlag const& enableDebuggingLayers);

        NamesList getUnsupportedLayers(NamesList& requestedLayers) const;

        NamesList _names;

    private:
        static NamesList constructNames(const bool enable);
    };

    class Extensions {
    public:
        using NamesList = std::vector<char const*> const;

        Extensions
            ( DebuggingLayersFlag const& printSupportedExtensions
            , ValidationLayers const& layers);

        NamesList _names;

    private:
        static NamesList constructNames(ValidationLayers::NamesList& layerNames);
    };

    class Instance {
    public:
        Instance
            ( AppName const& appName
            , ValidationLayers const& layers
            , Extensions const& extensions
            );
        ~Instance() = default;

        operator vk::Instance& ();
        operator vk::Instance const& () const;

        vk::Instance& operator*();
        vk::Instance const& operator*() const;
        vk::Instance* operator->();
        vk::Instance const*  operator->() const;

    private:
        Handle<vk::Instance> _instance;
    };

    class IDebugMessenger {
    public:
        virtual void callback
            ( vk::DebugUtilsMessageSeverityFlagsEXT severity
            , vk::DebugUtilsMessageTypeFlagsEXT type
            , vk::DebugUtilsMessengerCallbackDataEXT const* data
            ) = 0;
    };

    template <bool enableDebugging>
    class DebugMessenger;

    template <>
    class DebugMessenger<true> : public IDebugMessenger {
    public:
        DebugMessenger(Instance const& instance);

        void callback
            ( vk::DebugUtilsMessageSeverityFlagsEXT severity
            , vk::DebugUtilsMessageTypeFlagsEXT type
            , vk::DebugUtilsMessengerCallbackDataEXT const* data
            ) override;

    private:
        std::shared_ptr<nullptr_t> _resource;
    };

    template <>
    class DebugMessenger<false> : public IDebugMessenger {
    public:
        DebugMessenger();

        void callback
            ( vk::DebugUtilsMessageSeverityFlagsEXT severity
            , vk::DebugUtilsMessageTypeFlagsEXT type
            , vk::DebugUtilsMessengerCallbackDataEXT const* data
            ) override;
    };

    class Surface {
    public:
        Surface(Instance const& instance, glfw::Window& window);

    private:
        std::shared_ptr<vk::SurfaceKHR> _surface;
    };

    class PhysicalDevice {
    public:
        PhysicalDevice(Instance const& instance);

        //operator vk::PhysicalDevice& ();
        //operator vk::PhysicalDevice const& () const;

        //vk::PhysicalDevice& operator*();
        //vk::PhysicalDevice const& operator*() const;
        vk::PhysicalDevice* operator->();
        vk::PhysicalDevice const*  operator->() const;

    private:
        vk::PhysicalDevice _device;

        static bool suitable(vk::PhysicalDevice const& device);
    };

    class QueueFamilyIndices {
    public:
        QueueFamilyIndices(PhysicalDevice const& device);

    private:
        std::size_t graphicsFamily;
    };

    //struct SwapchainDetails {
    //  vk::SwapchainKHR swapchain;
    //  std::vector<vk::Image> images;
    //  std::vector<vk::ImageView> views;
    //  vk::Format format;
    //  vk::Extent2D extent;
    //};

    //struct GraphicsState {
    //  vulkan::Instance instance;
    //  std::optional<vk::DebugUtilsMessengerEXT> messenger;
    //  vk::SurfaceKHR surface;
    //  vk::PhysicalDevice phDevice;
    //  vk::Device device;
    //  vk::Queue graphicsQueue;
    //  vk::Queue presentQueue;
    //  SwapchainDetails swapchainDetails;
    //  vk::RenderPass renderPass;
    //  vk::PipelineLayout pipelineLayout;
    //  vk::Pipeline pipeline;
    //};

    //auto initVulkan
    //(uint32_t surfaceWidth, uint32_t surfaceHeight, GLFWwindow* window)
    //  -> GraphicsState;

}

void showWindow();

constexpr auto EnableDebugging =
#ifndef NDEBUG
    true;
#else
    false;
#endif

//struct Application {
//  glfw::Instance glfwInstance;
//  vulkan::Instance vulkanInstance;
//  std::unique_ptr<vulkan::IDebugMessenger> debugMessenger;
//  vulkan::Surface surface;
//};
using Application = std::tuple
    < glfw::Instance
    , vulkan::Instance
    , std::unique_ptr<vulkan::IDebugMessenger>
    , vulkan::Surface
    , vulkan::QueueFamilyIndices
    >;

int main(int, char**)
{
    auto app = di::make_injector
        ( di::bind<>.to(AppName{ "ndrtest" })
        , di::bind<>.to(vulkan::DebuggingLayersFlag{ EnableDebugging })
        , di::bind<vulkan::IDebugMessenger>.to<vulkan::DebugMessenger<EnableDebugging>>()
        , di::bind<>.to(glfw::Window::Height{ 600 })
        , di::bind<>.to(glfw::Window::Width{ 800 })
        ) 
        .create<Application>();

    std::cout << std::endl;
    return 0;
}
>------ Build started: Project: CMakeLists, Configuration: Debug ------
  [1/5] C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -I..\..\viz\include -IC:\Users\kostja\.conan\data\glfw\3.2.1\bincrafters\stable\package\8cf01e2f50fcd6b63525e70584df0326550364e1\include -IC:\VulkanSDK\1.1.101.0\Include /DWIN32 /D_WINDOWS /W3 /GR /EHsc  /MDd /Zi /Ob0 /Od /RTC1   -std:c++17 /showIncludes /Foviz\CMakeFiles\viz.dir\src\glfw.cpp.obj /Fdviz\CMakeFiles\viz.dir\viz.pdb /FS -c ..\..\viz\src\glfw.cpp
  [2/5] C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -I..\..\viz\include -IC:\Users\kostja\.conan\data\glfw\3.2.1\bincrafters\stable\package\8cf01e2f50fcd6b63525e70584df0326550364e1\include -IC:\VulkanSDK\1.1.101.0\Include /DWIN32 /D_WINDOWS /W3 /GR /EHsc  /MDd /Zi /Ob0 /Od /RTC1   -std:c++17 /showIncludes /Foviz\CMakeFiles\viz.dir\src\vulkan.cpp.obj /Fdviz\CMakeFiles\viz.dir\viz.pdb /FS -c ..\..\viz\src\vulkan.cpp
  [3/5] cmd.exe /C "cd . && C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /lib /nologo /machine:x64 /out:lib\viz.lib viz\CMakeFiles\viz.dir\src\glfw.cpp.obj viz\CMakeFiles\viz.dir\src\vulkan.cpp.obj  && cd ."
  [4/5] C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -I..\..\ndr\include -I..\..\viz\include -I..\..\extern\DI\include -IC:\Users\kostja\.conan\data\glfw\3.2.1\bincrafters\stable\package\8cf01e2f50fcd6b63525e70584df0326550364e1\include -IC:\VulkanSDK\1.1.101.0\Include /DWIN32 /D_WINDOWS /W3 /GR /EHsc  /MDd /Zi /Ob0 /Od /RTC1   -std:c++17 /showIncludes /FoCMakeFiles\ndrtest.dir\src\main.cpp.obj /FdCMakeFiles\ndrtest.dir\ /FS -c ..\..\src\main.cpp
  FAILED: CMakeFiles/ndrtest.dir/src/main.cpp.obj 
  C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -I..\..\ndr\include -I..\..\viz\include -I..\..\extern\DI\include -IC:\Users\kostja\.conan\data\glfw\3.2.1\bincrafters\stable\package\8cf01e2f50fcd6b63525e70584df0326550364e1\include -IC:\VulkanSDK\1.1.101.0\Include /DWIN32 /D_WINDOWS /W3 /GR /EHsc  /MDd /Zi /Ob0 /Od /RTC1   -std:c++17 /showIncludes /FoCMakeFiles\ndrtest.dir\src\main.cpp.obj /FdCMakeFiles\ndrtest.dir\ /FS -c ..\..\src\main.cpp
C:\src\main.cpp(45): warning C4996: 'boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create': creatable constraint not satisfied
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2780): note: see declaration of 'boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create'
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(1924): error C2440: 'initializing': cannot convert from 'initializer list' to 'wrapper'
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(1924): note: Invalid aggregate initialization
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(1152): note: see reference to function template instantiation 'auto boost::di::v1_1_0::scopes::unique::scope<TExpected,TGiven>::create<T,TName,TProvider>(const TProvider &) const' being compiled
          with
          [
              TExpected=vulkan::Instance,
              TGiven=vulkan::Instance,
              T=vulkan::Instance,
              TName=boost::di::v1_1_0::no_name,
              TProvider=provider_t
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2937): note: see reference to function template instantiation 'auto boost::di::v1_1_0::scopes::deduce::scope<TExpected,TGiven>::create<T,TName,provider_t>(const TProvider &)' being compiled
          with
          [
              TExpected=vulkan::Instance,
              TGiven=vulkan::Instance,
              T=vulkan::Instance,
              TName=boost::di::v1_1_0::no_name,
              TProvider=provider_t
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2847): note: see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create_impl__<TIsRoot,vulkan::Instance,boost::di::v1_1_0::no_name>(void) const' being compiled
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none,
              TIsRoot=boost::di::v1_1_0::aux::false_type
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2413): note: see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create_impl<boost::di::v1_1_0::aux::false_type,vulkan::Instance>(const boost::di::v1_1_0::aux::type<vulkan::Instance> &) const' being compiled
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(1923): note: see reference to function template instantiation 'auto boost::di::v1_1_0::core::provider<ctor_t,TName,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>>::get<memory>(const TMemory &) const' being compiled
          with
          [
              TName=boost::di::v1_1_0::no_name,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none,
              TMemory=memory
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(1152): note: see reference to function template instantiation 'auto boost::di::v1_1_0::scopes::unique::scope<TExpected,TGiven>::create<T,TName,TProvider>(const TProvider &) const' being compiled
          with
          [
              TExpected=std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<vulkan::IDebugMessenger>>,vulkan::Surface,vulkan::QueueFamilyIndices>,
              TGiven=std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<vulkan::IDebugMessenger>>,vulkan::Surface,vulkan::QueueFamilyIndices>,
              T=Application,
              TName=boost::di::v1_1_0::no_name,
              TProvider=provider_t
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2937): note: see reference to function template instantiation 'auto boost::di::v1_1_0::scopes::deduce::scope<TExpected,TGiven>::create<T,TName,provider_t>(const TProvider &)' being compiled
          with
          [
              TExpected=std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<vulkan::IDebugMessenger>>,vulkan::Surface,vulkan::QueueFamilyIndices>,
              TGiven=std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<vulkan::IDebugMessenger>>,vulkan::Surface,vulkan::QueueFamilyIndices>,
              T=Application,
              TName=boost::di::v1_1_0::no_name,
              TProvider=provider_t
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2847): note: see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create_impl__<TIsRoot,std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<_Ty>>,vulkan::Surface,vulkan::QueueFamilyIndices>,boost::di::v1_1_0::no_name>(void) const' being compiled
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none,
              TIsRoot=boost::di::v1_1_0::aux::true_type,
              _Ty=vulkan::IDebugMessenger
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2782): note: see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>::create_impl<boost::di::v1_1_0::aux::true_type,std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<vulkan::IDebugMessenger,std::default_delete<_Ty>>,vulkan::Surface,vulkan::QueueFamilyIndices>>(const boost::di::v1_1_0::aux::type<std::tuple<glfw::Instance,vulkan::Instance,std::unique_ptr<_Ty,std::default_delete<_Ty>>,vulkan::Surface,vulkan::QueueFamilyIndices>> &) const' being compiled
          with
          [
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none,
              _Ty=vulkan::IDebugMessenger
          ]
  ..\..\src\main.cpp(45): note: see reference to function template instantiation 'T boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,vulkan::DebugMessenger<true>,TName,TPriority,TCtor>,dependency,dependency>::create<Application,0>(void) const' being compiled
          with
          [
              T=Application,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
  ..\..\src\main.cpp(45): note: see reference to function template instantiation 'T boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,vulkan::DebugMessenger<true>,TName,TPriority,TCtor>,dependency,dependency>::create<Application,0>(void) const' being compiled
          with
          [
              T=Application,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              TName=boost::di::v1_1_0::no_name,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2464): error C2182: 'wrapper_': illegal use of type 'void'
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2937): note: see reference to class template instantiation 'boost::di::v1_1_0::core::wrapper_impl<T,wrapper_t,int>' being compiled
          with
          [
              T=vulkan::Instance
          ]
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2945): error C2440: 'initializing': cannot convert from 'initializer list' to 'boost::di::v1_1_0::core::wrapper_impl<T,wrapper_t,int>'
          with
          [
              T=vulkan::Instance
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2937): note: Invalid aggregate initialization
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2414): error C2672: 'boost::di::v1_1_0::core::provider<ctor_t,TName,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>>::get_impl': no matching overloaded function found
          with
          [
              TName=boost::di::v1_1_0::no_name,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2413): error C2783: 'auto boost::di::v1_1_0::core::provider<ctor_t,TName,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>>::get_impl(const TMemory &,TArgs &&...) const': could not deduce template argument for '__formal'
          with
          [
              TName=boost::di::v1_1_0::no_name,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2417): note: see declaration of 'boost::di::v1_1_0::core::provider<ctor_t,TName,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,dependency,dependency,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,dependency,dependency>>::get_impl'
          with
          [
              TName=boost::di::v1_1_0::no_name,
              TConfig=boost::di::v1_1_0::config,
              TScope=boost::di::v1_1_0::scopes::deduce,
              TExpected=vulkan::IDebugMessenger,
              T=vulkan::DebugMessenger<true>,
              TPriority=void,
              TCtor=boost::di::v1_1_0::core::none
          ]
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(1356): error C2182: '<Unknown>': illegal use of type 'void'
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(1924): note: see reference to class template instantiation 'boost::di::v1_1_0::wrappers::unique<boost::di::v1_1_0::scopes::unique,void>' being compiled
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(1357): error C2182: 'object': illegal use of type 'void'
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2945): error C2440: 'initializing': cannot convert from 'initializer list' to 'boost::di::v1_1_0::core::wrapper_impl<T,wrapper_t,int>'
          with
          [
              T=Application
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2937): note: Invalid aggregate initialization
C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI\di.hpp(2782): error C2440: 'type cast': cannot convert from 'void' to 'T &&'
          with
          [
              T=Application
          ]
  C:\Users\kostja\Dev\Algorithms\NDR\extern\DI\include\DI/di.hpp(2782): note: Expressions of type void cannot be converted to other types
  ninja: build stopped: subcommand failed.

Build failed.

I used version 1.1.0

nvevg commented 4 years ago

Would you mind if I ask you to provide lesser code snippet (at least which is not using any external APIs)? I feel eager to fix that, but with the example you'd provided it is hard to reproduce the problem.

kanstantsin-chernik commented 4 years ago

@heilkn do you still experience the problem? Could you provide simplified code snippet?

heilkn commented 4 years ago

I am sorry for the delay. I will create a shorter example.

Kind regards

Konstantin


From: kchernik notifications@github.com Sent: Monday, 14 October 2019 16:28 To: boost-experimental/di Cc: Konstantin Heil; Mention Subject: Re: [boost-experimental/di] Adding default Destructor breaks Compilation (#428)

@heilkn do you still experience the problem? Could you provide simplified code snippet?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

heilkn commented 4 years ago

Ok, I removed as much as I could and the problem seems to be the unique_ptr member. For me, compilation stops working with visual studio 2017 when uncommenting the defaulted destructor. I am sorry, for not taken the time to create the minimal example in the first place.

#include "di.hpp"
namespace di = boost::di;

#include <memory>
#include <tuple>

class Instance {
public:
    Instance
        () {}

    //~Instance() = default;
private:
    std::unique_ptr<int> _handle;
};

using Application = std::tuple
    < Instance
    >;

int main(int, char**)
{
    auto app = di::make_injector
        (       ).create<Application>();

    return 0;
}
kanstantsin-chernik commented 4 years ago

Your issues has nothing to do with boost di. The problem is defining a destructor cause removal of implicitly generated move constructor (as well as copy but in your case std::unique has already took care of it)

You can check and see the same result:

  Application app;
  auto app1 = move(app);

You can easily fix it by providing move constructor. Instance(Instance&& other) noexcept = default;

A couple of links:

heilkn commented 4 years ago

Thank you very much for the response. In that case a nicer error message would have been useful for why the type did not satisfy the creatable constraint. I thought adding the generated destructor explicitly does not change anything.

Also, it would be really nice if one could construct non-copyable, non-movable types.