-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] bind templates and CHANGELOG update for 1.0.2
* 1.0.2 CHANGELOG update. * Bind templates example.
- Loading branch information
1 parent
a4fce16
commit 8211906
Showing
7 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,3 @@ endif() | |
add_subdirectory(example) | ||
add_subdirectory(extension) | ||
add_subdirectory(test) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters