Skip to content
Snippets Groups Projects
  • Ben Cumming's avatar
    Fix bug with comparison operator for spikes (#316) · 1a58e003
    Ben Cumming authored
    The less than operator for spikes was not in the nest::mc namespace,
    so it was not being picked up by STL algoriths and containers.
    This patch makes it a friend operator of the `nest::mc::basic_spike`,
    and adds some unit tests to varify that STL algorithms can use
    containers of spikes.
    
    fixes #315.
    1a58e003
spike.hpp 945 B
#pragma once

#include <ostream>
#include <type_traits>

#include <common_types.hpp>

namespace nest {
namespace mc {

template <typename I>
struct basic_spike {
    using id_type = I;

    id_type source = id_type{};
    time_type time = -1;

    basic_spike() = default;

    basic_spike(id_type s, time_type t):
        source(s), time(t)
    {}

    /// Less than comparison operator for nest::mc::spike<> values:
    /// spikes are ordered by spike time, for use in sorting and queueing.
    friend bool operator<(basic_spike lhs, basic_spike rhs) {
        return lhs.time < rhs.time;
    }
};

/// Standard specialization:
using spike = basic_spike<cell_member_type>;

} // namespace mc
} // namespace nest

// Custom stream operator for printing nest::mc::spike<> values.
template <typename I>
std::ostream& operator<<(std::ostream& o, nest::mc::basic_spike<I> s) {
    return o << "spike[t " << s.time << ", src " << s.source << "]";
}