Last active
January 7, 2022 15:42
-
-
Save hjroh0315/fef937f6607896fe95d58990197956ee to your computer and use it in GitHub Desktop.
range-based for이 가능한 문자열제외 모든 타입에 대해 cin이 가능하게 해줍니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <type_traits> | |
#include <vector> | |
template<typename T> | |
struct is_string | |
: public std::disjunction< | |
std::is_same<char *, typename std::decay_t<T>>, | |
std::is_same<const char *, typename std::decay_t<T>>, | |
std::is_same<std::string, typename std::decay_t<T>> | |
> { | |
}; | |
namespace isiter | |
{ | |
using std::begin; | |
using std::end; | |
template <typename T> | |
auto is_iterable_impl(int) | |
-> decltype ( | |
begin(std::declval<T&>()) != end(std::declval<T&>()), | |
++std::declval<decltype(begin(std::declval<T&>()))&>(), | |
*begin(std::declval<T&>()), | |
std::true_type{}); | |
template <typename T> | |
std::false_type is_iterable_impl(...); | |
} | |
template <typename T> | |
using is_iterable = decltype(isiter::is_iterable_impl<T>(0)); | |
template <typename T, | |
typename = typename std::enable_if<is_iterable<T>::value&&!is_string<T>::value>::type> | |
std::istream& operator>> (std::istream& i,T& t) { | |
for(auto&k:t)i>>k; | |
return i; | |
} | |
using namespace std; | |
int main() | |
{ | |
int a[5]; | |
cin>>a; | |
for(int k:a)cout<<k<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment