vendredi 3 avril 2015

c++11 array initialization won't call copy constructor

I'm making a little class that uses an array templated on its size. Here's some code...


.hpp



template <size_t N>
class KeyCombinationListener
{
public:
KeyCombinationListener(
const std::array<sf::Keyboard::Key, N>& sequence, std::function<void (void)> fn
);

private:
std::array<sf::Keyboard::Key, N> combo;
std::function<void (void)> callback;
};


.cc



template <size_t N>
KeyCombinationListener<N>::KeyCombinationListener(
const array<sf::Keyboard::Key, N>& sequence, function<void (void)> fn
) : combo(sequence), progress{begin(combo)}, callback{fn}
{

}


In the member initialization of the constructor, I can't use combo{sequence} as the initializer because it only accepts sf::Keyboard::Key types. This makes sense if it's asking for an initializer_list, but this seems strange to me. With other standard containers I can call a copy constructor using {} notation just fine. Is this a quirk with std::array? Or maybe a bug in my clang?


Just in case it helps, here's my clang version:



Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Selected multilib: .;@m64

Aucun commentaire:

Enregistrer un commentaire