These are chat archives for elemental/chat

18th
Sep 2016
Jack Poulson
@poulson
Sep 18 2016 16:52
Riddle me this, what is wrong with this code?!?
#include <iostream>
#include <sstream>

namespace foo {

struct Rectangle { double height, width; };
std::ostream& operator<<(std::ostream& os, const Rectangle& a) { return os; }

inline void BuildStream(std::ostringstream& os) {  }

template<typename T, typename... Args>
inline void BuildStream
(std::ostringstream& os, const T& item, const Args& ...args) {
 os << item;
 BuildStream(os, args...);
}

} // namespace foo

namespace bar {

using Rectangle = foo::Rectangle;

inline void BuildStream(std::ostringstream& os) { }

template<typename T, typename... Args>
inline void BuildStream
(std::ostringstream& os, const T& item, const Args& ...args) {
 os << item;
 BuildStream(os, args...);
}

} // namespace bar

int main(int argc, char* argv[]) {
 std::ostringstream os;
 bar::BuildStream(os, 1, 2);
 bar::BuildStream(os, bar::Rectangle(), bar::Rectangle());
 return 0;
}
Jack Poulson
@poulson
Sep 18 2016 17:52
This is due to two issues (one offline and one in libskylark) being reported claiming that there was a mistake in Elemental's namespacing. Both issues seem to be caused by argument-dependent lookup not being widely appreciated.
Ryan H. Lewis
@rhl-
Sep 18 2016 19:17
Wow.
Jack Poulson
@poulson
Sep 18 2016 19:20
yes, ADL seems to be somewhat of a hack
the story Koenig tells in his blog post on Dr. Dobbs gives that away
but I am surprised no preference is given to the current namespace