- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
#include <iostream>
#include <memory>
struct Test {
~Test() { std::cout << "~Test\n"; }
};
int main() {
std::shared_ptr<void> ptr( new Test );
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+39
#include <iostream>
#include <memory>
struct Test {
~Test() { std::cout << "~Test\n"; }
};
int main() {
std::shared_ptr<void> ptr( new Test );
return 0;
}
http://ideone.com/xXPWhE
Но:
#include <iostream>
#include <memory>
struct Test
{
~Test() { std::cout << "~Test\n"; }
};
int main() {
std::shared_ptr<void> ptr( (void*) new Test );
return 0;
}
http://ideone.com/jhNvpJ
+46
//Сом ненужный щит
#include <iostream>
using namespace std;
#include <string>
#include <iostream>
struct Tracer {
Tracer(void)
:m_name("(none)")
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const std::string & name)
:m_name(name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const Tracer & other)
:m_name(other.m_name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const Tracer && other)
:m_name(other.m_name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer & operator=(const Tracer & other) {
m_name = other.m_name;
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
return *this;
}
Tracer & operator=(const Tracer && other) {
m_name = other.m_name;
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
return *this;
}
~Tracer() {
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
m_name="You looser!";
}
std::string m_name;
};
//Тот щит, ради чего всё затевалось
template<class T> const T& Min(const T &x, const T &y) { return (x.m_name < y.m_name) ? x : y; }
int main() {
const Tracer& mr = Min(Tracer("a"), Tracer("b"));
cout<<"Some work with mr: "<<mr.m_name<<endl;
return 0;
}
[b] Tracer::Tracer(const string&)
[a] Tracer::Tracer(const string&)
[a] Tracer::~Tracer()
[b] Tracer::~Tracer()
Some work with mr:
Этож сколько я коммитов сделал с возвратом константной ссылки на константный параметр.
+36
t = Min(::std::cref(x), ::std::cref(y));
//или в зависимости от ситуации
t = Min(::std::move(x), ::std::move(y));
Абстракционизм или Кубизм?
+139
public boolean mkdir()
Creates the directory named by this abstract pathname.
Returns: true if and only if the directory was created; false otherwise
P.S. В java.nio сделали адекватную функцию, еще один гвоздь в крышку гроба шестерки.
+70
public class ImportException extends Exception {
public static final int NOT_CRITICAL = 1;
public static final int CRITICAL = 2;
private int criticality = NOT_CRITICAL;
public ImportException(String message) {
this.message = message;
}
/**
* С критичностью
* @param message
* @param criticality
*/
public ImportException(String message, int criticality) {
this.message = message;
this.criticality = criticality;
}
public int getCriticality() {
return criticality;
}
public void setCriticality(int criticality) {
this.criticality = criticality;
}
}
изобретение типа bool
+64
// Полный импорт
private void fullImport(Collection<Entity> entities, File unzippedDir)
throws IOException {
спасибо за подсказку
+67
File unzippedDir = File.createTempFile("po.", null);
unzippedDir.delete();
unzippedDir = new File(unzippedDir.getAbsoluteFile() + ".dir");
ну да, а посмотреть сигнатуру метода, который вызываем, не судьба, лучше изобрести велосипед
public static File createTempFile(String prefix, String suffix) throws IOException
СУФФИКС!!!
+140
ЗА РУСЬ!!!
+69
public List<ImportException> importFiles() {
Collection<ImportException> exceptions = new ArrayList<ImportException>();
/* весь метод exceptions ссылается на этот список */
return (List<ImportException>) exceptions;
}
Полиморфизм ёпт
+142
Травля "kegdan`a" объявляется открытой.