Skip to content

Commit

Permalink
[example] bind templates and CHANGELOG update for 1.0.2
Browse files Browse the repository at this point in the history
* 1.0.2 CHANGELOG update.
* Bind templates example.
  • Loading branch information
kris-jusiak committed Jan 5, 2018
1 parent a4fce16 commit 8211906
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 22 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ endif()
add_subdirectory(example)
add_subdirectory(extension)
add_subdirectory(test)

42 changes: 28 additions & 14 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
## [1.0.2] - 2017-XX-XX
- **Additions**
- Support for Clang-4.0
- Support for GCC-7
- Support for MSVC-2017
>
- **Core**
- [Support for injecting templates/concepts]()
## [1.0.2] - 2018-01-04
- **Additions**
- Support for Clang-4.0
- Support for GCC-7
- Support for MSVC-2017
- Fixed support for MSVC-2015 Update 3
>
- **Core**
- [Support for injecting templates/concepts](http://boost-experimental.github.io/di/examples/index.html#binding-templates)
>
- **Extensions**
- [Extensions are now avaialbe as header files](https://github.com/boost-experimental/di/tree/cpp14/extension/include/boost/di/extension)
- [Extensible Injector](http://boost-experimental.github.io/di/extensions/index.html#extensible-injector)
- [Shared Factory](http://boost-experimental.github.io/di/extensions/index.html#shared-factory)
>
- **Bug Fixes**
- [Implementation class cannot be marked as `final`](https://github.com/boost-experimental/di/issues/249)
- [Creation with Factory doesn't allow to pass exceptions through](https://github.com/boost-experimental/di/issues/239)
- [Bound policy doesn't work with multiple bindings](https://github.com/boost-experimental/di/issues/238)
- [Problems compiling with _GLIBCXX_DEBUG defined](https://github.com/boost-experimental/di/issues/235)
- [Exception in ctor not propagated](https://github.com/boost-experimental/di/issues/227)
- [Unable to compile with VS 2017 RC, VS 2015 works fine](https://github.com/boost-experimental/di/issues/226)
- [Broken under VS2015 Update 3](https://github.com/boost-experimental/di/issues/219)
>
- **Contributions**
- Kanstantsin Chernik

## [1.0.1] - 2016-05-04
- **Breaking Changes**
Expand All @@ -16,8 +34,8 @@
- Support for GCC-6
>
- **Extensions**
- [Contextual Bindings](http://boost-experimental.github.io/di/extensions/index.html#contextual-bindings)
- [Serialize](http://boost-experimental.github.io/di/extensions/index.html#serialize)
- [Contextual Bindings](http://boost-experimental.github.io/di/extensions/index.html#contextual-bindings)
- [Serialize](http://boost-experimental.github.io/di/extensions/index.html#serialize)
>
- **Bug Fixes**
- [Link error if di.hpp is included in two cpp-files](https://github.com/boost-experimental/di/issues/212)
Expand All @@ -40,10 +58,6 @@

---

* TODO

* [https://waffle.io/boost-experimental/di](https://waffle.io/boost-experimental/di)

[1.0.2]: https://github.com/boost-experimental/di/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/boost-experimental/di/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/boost-experimental/di/compare/v0.5.0...v1.0.0
Expand Down
4 changes: 4 additions & 0 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [Forward Bindings](#forward-bindings)
* [Multiple Bindings](#multiple-bindings)
* [Binding Non-owning Pointer](#binding-non-owning-pointer)
* [Binding Templates](#binding-templates)
* [Automatic Injection](#automatic-injection)
* [Constructor Signature](#constructor-signature)
* [Constructor Injection](#constructor-injection)
Expand Down Expand Up @@ -39,6 +40,9 @@
###Binding Non-owning Pointer
![CPP](https://raw.githubusercontent.com/boost-experimental/di/cpp14/example/bind_non_owning_ptr.cpp)

###Binding Templates
![CPP](https://raw.githubusercontent.com/boost-experimental/di/cpp14/example/bind_templates.cpp)

###Automatic Injection
![CPP](https://raw.githubusercontent.com/boost-experimental/di/cpp14/example/automatic_injection.cpp)

Expand Down
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endfunction()
example(annotations)
example(automatic_injection)
example(bind_non_owning_ptr)
example(bind_templates)
example(bindings)
example(configuration)
example(constructor_injection)
Expand Down
3 changes: 2 additions & 1 deletion example/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ test-suite example :
modules/controller.cpp
modules/main.cpp
: -Imodules -DBOOST_DI_CFG_FWD="\"class config;\"" -DBOOST_DI_CFG=config
]
]
[ example annotations.cpp ]
[ example automatic_injection.cpp ]
[ example bind_non_owning_ptr.cpp ]
[ example bind_templates.cpp ]
[ example bindings.cpp ]
[ example configuration.cpp ]
[ example constructor_injection.cpp ]
Expand Down
46 changes: 46 additions & 0 deletions example/bind_templates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright (c) 2012-2018 Kris Jusiak (kris at jusiak dot net)
//
// 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)
//
//<-
#include <cassert>
#include <type_traits>
//->
#include <boost/di.hpp>

namespace di = boost::di;

#if defined(_MSC_VER)
class Type;
class Number;
#endif

template <class T = class Type, class TNumber = class Number>
struct hello {
using type = T;
explicit hello(const TNumber& number) : number{number} {}
TNumber number;
};

template <class T = int>
struct world {
using type = T;
};

int main() {
auto i = 42;

// clang-format off
const auto injector = di::make_injector(
di::bind<class Type>().to<world>()
, di::bind<class Number>().to<int>(i)
);
// clang-format on

const auto hw = injector.create<hello>();

static_assert(std::is_same<int, decltype(hw)::type::type>{}, "Type != int");
assert(42 == hw.number);
}
14 changes: 8 additions & 6 deletions example/try_it.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

namespace di = boost::di;

#if defined(_MSC_VER)
class Greater;
#endif

struct iworld {
virtual ~iworld() noexcept = default;
};
Expand All @@ -25,10 +29,8 @@ struct hello {
}
};

class Greater;

/// aggregate initialization `example{hello, world}`
template <class T = Greater>
template <class T = class Greater>
struct example {
T h;
iworld& w;
Expand All @@ -37,9 +39,9 @@ struct example {
int main() {
// clang-format off
const auto injector = di::make_injector(
di::bind<iworld>().to<world>() // bind interface to implementation
, di::bind<>().to(42) // bind int to value 42
, di::bind<Greater>().to<hello>() // bind template to type
di::bind<iworld>().to<world>() // bind interface to implementation
, di::bind<>().to(42) // bind int to value 42
, di::bind<class Greater>().to<hello>() // bind template to type
);
// clang-format off

Expand Down

0 comments on commit 8211906

Please sign in to comment.