Perhaps the nicest solution, if you are using the containers of the standard library, is the following:
template <typename ItType>
auto buildBinaryTree (ItType start, ItType end) -> Node<typename ItType::value_type>*
UPDATE: We need an extra level of indirection with value_type
as follows: std::iterator_traits<ItType>::value_type
(kindly pointed out by Praetorian).
Another solution is to change
auto buildBinaryTree (ItType start, ItType end) -> Node<decltype(*start)>*
to this (You may need to #include <type_traits>
):
auto buildBinaryTree (ItType start, ItType end) -> Node<typename std::remove_reference<decltype(*start)>::type>*
The gcc error message was clear:
error: cannot convert
Node<int&>*
toNode<int>*
in return
apparently, you are using clang, which, unfortunately, doesn't give such a clear error message... :(