Code: Select all
template <class _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
2)operator ( ). How is that operator function being called externally? (syntax wise)
std::less<T> ( &x, &y) will call the less's operator ( ) function?
Code: Select all
template<typename T, typename Comp = std::less<T>>
class PriorityQ
{
public:
Comp comp;
std::vector<T> v;
unsigned n;
public:
PriorityQ() : n(0) {}
PriorityQ(Comp comp_) : comp(comp_), n(0) {}
size_t size() const { return n; }
void clear() { n = 0; }
bool empty() { return n == 0; }
void push(const T &x)
{
assert(v.size() >= n);
if (v.size() == n)
v.push_back(x);
/**
* @brief Append a single character.
* @param c Character to append.
*/
else
v[n] = x;
++n;
std::push_heap(&v[0], &v[n], comp);
}
/**
* @brief Push an element onto a heap.
* @param first Start of heap.
* @param last End of heap + element.
* @ingroup heap
*
* This operation pushes the element at last-1 onto the valid heap over the
* range [first,last-1). After completion, [first,last) is a valid heap.
*/push_back is used when vector size is =n and push_heap is used when vector size > n
what's the actual difference between these two functions from a memory stand point?
Code: Select all
for (const auto &p : top->nets())
{
if (p.second->is_constant())
{
if (p.second->constant() == Value::ONE)
const1 = p.second;
else
{
assert(p.second->constant() == Value::ZERO);
const0 = p.second;
}
}
if (const0 && const1)
break;
}