Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ReallyWeirdCat authored May 14, 2023
1 parent 3077d15 commit 87b488b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ПР14/3/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "setgetter.h"
#include <iostream>
#include <set>

int main()
{
std::set<double> numeros;
std::cout << "got: " << setgetter::get(numeros) << std::endl;


numeros.insert(3);
std::cout << "added 3;" << std::endl;
std::cout << "got: " << setgetter::get(numeros) << std::endl;

}
23 changes: 23 additions & 0 deletions ПР14/3/setgetter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <set>
#include <iostream>
#include <stdexcept>


class setgetter
{
public:
template <class T>
static T get(std::set<T> set)
{
try {
if (set.begin() == set.end()) throw std::out_of_range("Out of range");
return *set.begin();
}
catch (std::out_of_range& e)
{
std::cout << e.what() << std::endl;
return T();
}
}
};

0 comments on commit 87b488b

Please sign in to comment.