usefulTools/src/tools/tools.hpp
2024-09-17 12:32:47 +08:00

63 lines
1.7 KiB
C++

#pragma once
#include <iostream>
#include <ostream>
#include <sstream>
#define NAME_VALUE(v)#v," : ",(v)
namespace zt {
template<typename T>
class Range{
private:
T _start,_end,_step;
public:
// constexpr Range()=delete;
constexpr Range(const T start,const T end,const T step)noexcept:_start(start),_end(end),_step(step){}
constexpr Range(const T start,const T end)noexcept:Range(start,end,1){}
constexpr Range(const T end)noexcept:Range(1,end,1){}
struct Iterator{
T current,step;
constexpr Iterator()=delete;
constexpr Iterator(const T start,const T step)noexcept:current(start),step(step){}
constexpr bool operator!=(const Iterator &other)const noexcept{
return current<other.current;
}
constexpr Iterator& operator++()noexcept{
current+=step;
return *this;
}
constexpr T operator*()const noexcept{
return current;
}
};
constexpr Iterator begin(){
return Iterator(_start,_step);
}
constexpr Iterator end(){
return Iterator(_end,_step);
}
};
template<typename ...Args>
inline void print(std::ostream &os,const Args&...args){
std::stringstream ss;
((ss<<args),...);
os<<ss.str();
return;
}
template<typename ...Args>
inline void print(const Args&...args){
print(std::cin,args...);
return;
}
template<typename ...Args>
inline void eprint(const Args&...args){
print(std::cerr,args...);
return;
}
}