update
This commit is contained in:
parent
ff91daf4b7
commit
1095672253
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.vscode
|
||||
.xmake
|
||||
build
|
15
README.md
15
README.md
@ -1,2 +1,17 @@
|
||||
# VideoShows
|
||||
|
||||
## 如何构建?
|
||||
>请先安装xmake并执行
|
||||
```bash
|
||||
|
||||
xmake -v
|
||||
xmake r <target name>
|
||||
|
||||
```
|
||||
>即可,如果你想用xmake构建可以使用
|
||||
```bash
|
||||
|
||||
xmake project -k xmake
|
||||
|
||||
```
|
||||
>生成CMakeLists.txt
|
54
printAndRange/printAndRange.cpp
Normal file
54
printAndRange/printAndRange.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
template<typename ...Args>
|
||||
void print(const Args&...args){
|
||||
std::stringstream ss;
|
||||
((ss<<args),...);
|
||||
std::cout<<ss.str();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(const int argc,const char* argv[]){
|
||||
for(auto i:Range(1,11,2)){
|
||||
for(auto j:Range(1,11,2)){
|
||||
print("[","i: ",i," ,j: ",j,"] ");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
print("\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user